@scalable.software/pin 0.2.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.
package/dist/Pin.d.ts ADDED
@@ -0,0 +1,210 @@
1
+ /**
2
+ * @module Component
3
+ */
4
+ import { Component, Template } from "@scalable.software/component";
5
+ import { type Configuration } from "@scalable.software/component";
6
+ import { type Attributes, type Visibility, type Statuses, type Handler } from "./Pin.meta.js";
7
+ /**
8
+ * Configuration required for components with custom layout and style
9
+ * @category Configuration
10
+ */
11
+ export declare const configuration: Configuration;
12
+ /**
13
+ * A pin button that can be:
14
+ * 1. pinned and unpinned
15
+ * 2. hidden and shown
16
+ * @category Components
17
+ */
18
+ export declare class Pin extends Component {
19
+ /**
20
+ * The tag name of the component
21
+ * @category Configuration
22
+ */
23
+ static get Tag(): "pin-button";
24
+ /**
25
+ * Only attributes defined the Attributes object will be observed in DOM
26
+ * @category Configuration
27
+ */
28
+ static get Attributes(): Attributes;
29
+ /**
30
+ * Wait for the component to be defined before returning a collection of the component in the DOM
31
+ * @category Utilities
32
+ */
33
+ static get: () => Promise<Pin[]>;
34
+ /**
35
+ * Helper function to load the component template into DOM
36
+ * @category Utilities
37
+ */
38
+ static Template: Template;
39
+ /**
40
+ * Cache element references to improve performance
41
+ * @category State
42
+ * @hidden
43
+ */
44
+ protected elements: {
45
+ icon: HTMLDivElement | null;
46
+ };
47
+ /**
48
+ * Internal Visibility state of the component
49
+ * @category State
50
+ * @default Visible.YES
51
+ * @hidden
52
+ */
53
+ private _visible;
54
+ /**
55
+ * Internal Status state of the component
56
+ * @category State
57
+ * @default
58
+ * @hidden
59
+ */
60
+ private _status;
61
+ /**
62
+ * on triggered when any event is triggered
63
+ * @category Events
64
+ * @hidden
65
+ */
66
+ private _on;
67
+ /**
68
+ * onhide triggered when pin visibility changes to hidden
69
+ * @category Events
70
+ * @hidden
71
+ */
72
+ private _onhide;
73
+ /**
74
+ * onshow triggered when pin visibility changes to visible
75
+ * @category Events
76
+ * @hidden
77
+ */
78
+ private _onshow;
79
+ /**
80
+ * onpin triggered when pin status changes to pinned
81
+ * @category Events
82
+ * @hidden
83
+ */
84
+ private _onpin;
85
+ /**
86
+ * onunpin triggered when pin state changes to unpinned
87
+ * @category Events
88
+ * @hidden
89
+ */
90
+ private _onunpin;
91
+ constructor();
92
+ /**
93
+ * Get and Sets the visibility of the pin button
94
+ * @category State
95
+ */
96
+ get visible(): Visibility;
97
+ set visible(visible: Visibility);
98
+ /**
99
+ * Get and Sets the status of the pin button
100
+ * @category State
101
+ */
102
+ get status(): Statuses;
103
+ set status(status: Statuses);
104
+ /**
105
+ * Triggered on any event
106
+ * @event
107
+ * @category Events
108
+ */
109
+ set on(handler: Handler);
110
+ /**
111
+ * Triggered via `.hide()`
112
+ * @event
113
+ * @category Events
114
+ */
115
+ set onhide(handler: Handler);
116
+ /**
117
+ * Triggered via `.show()`
118
+ * @event
119
+ * @category Events
120
+ */
121
+ set onshow(handler: Handler);
122
+ /**
123
+ * Triggered via `.pin()`
124
+ * @event
125
+ * @category Events
126
+ */
127
+ set onpin(handler: Handler);
128
+ /**
129
+ * Triggered via `.unpin()`
130
+ * @event
131
+ * @category Events
132
+ */
133
+ set onunpin(handler: Handler);
134
+ /**
135
+ * Hide the pin button when it is visible
136
+ * @category Operations
137
+ */
138
+ hide: () => "no";
139
+ /**
140
+ * Show the pin button when it is hidden
141
+ * @category Operations
142
+ */
143
+ show: () => "yes";
144
+ /**
145
+ * Pin the pin button when it is unpinned
146
+ * @category Operations
147
+ */
148
+ pin: () => "pinned";
149
+ /**
150
+ * Unpin the pin button when it is pinned
151
+ * @category Operations
152
+ */
153
+ unpin: () => "unpinned";
154
+ /**
155
+ * Toggle the pin button between pinned and unpinned
156
+ * @category Operations
157
+ */
158
+ toggle: () => "pinned" | "unpinned";
159
+ /**
160
+ * List operations to perform for selected attributes being observed in the DOM.
161
+ * @category Configuration
162
+ * @hidden
163
+ */
164
+ protected _attributeHandlers: {
165
+ visible: (value: any) => any;
166
+ status: (value: any) => any;
167
+ };
168
+ /**
169
+ * Initialize component attributes with default values
170
+ * @category Configuration
171
+ * @hidden
172
+ */
173
+ protected _initialize: () => void;
174
+ /**
175
+ * Cache element references to improve performance
176
+ * @category Configuration
177
+ * @hidden
178
+ */
179
+ protected _cacheElements: () => HTMLDivElement;
180
+ /**
181
+ * Called by the connectedCallback prototypical method
182
+ * @category Configuration
183
+ * @hidden
184
+ */
185
+ protected _addEventListeners: () => void;
186
+ /**
187
+ * Called by the disconnectedCallback prototypical method
188
+ * @category Configuration
189
+ * @hidden
190
+ */
191
+ protected _removeEventListeners: () => void;
192
+ /**
193
+ * Initialize component state with default values
194
+ * @category State
195
+ * @hidden
196
+ */
197
+ private _initializeState;
198
+ /**
199
+ * Cache icon element reference to improve performance
200
+ * @category State
201
+ * @hidden
202
+ */
203
+ private _cacheIcon;
204
+ /**
205
+ * Handles the click event
206
+ * @category Gesture
207
+ * @hidden
208
+ */
209
+ private _handleClick;
210
+ }
package/dist/Pin.js ADDED
@@ -0,0 +1,276 @@
1
+ /**
2
+ * @module Component
3
+ */
4
+ import { Component, Template } from "@scalable.software/component";
5
+ import { Tag, Attribute, Visible, Status, Event, Gesture } from "./Pin.meta.js";
6
+ /**
7
+ * Configuration required for components with custom layout and style
8
+ * @category Configuration
9
+ */
10
+ export const configuration = {
11
+ url: import.meta.url,
12
+ template: {
13
+ id: Tag,
14
+ },
15
+ css: {
16
+ name: "Pin.style.css",
17
+ },
18
+ };
19
+ /**
20
+ * A pin button that can be:
21
+ * 1. pinned and unpinned
22
+ * 2. hidden and shown
23
+ * @category Components
24
+ */
25
+ export class Pin extends Component {
26
+ /**
27
+ * The tag name of the component
28
+ * @category Configuration
29
+ */
30
+ static get Tag() {
31
+ return Tag;
32
+ }
33
+ /**
34
+ * Only attributes defined the Attributes object will be observed in DOM
35
+ * @category Configuration
36
+ */
37
+ static get Attributes() {
38
+ return Attribute;
39
+ }
40
+ /**
41
+ * Wait for the component to be defined before returning a collection of the component in the DOM
42
+ * @category Utilities
43
+ */
44
+ static get = async () => (await customElements.whenDefined(Pin.Tag)) &&
45
+ Array.from(document.querySelectorAll(Pin.Tag));
46
+ /**
47
+ * Helper function to load the component template into DOM
48
+ * @category Utilities
49
+ */
50
+ static Template = new Template(import.meta.url);
51
+ /**
52
+ * Cache element references to improve performance
53
+ * @category State
54
+ * @hidden
55
+ */
56
+ elements = { icon: null };
57
+ /**
58
+ * Internal Visibility state of the component
59
+ * @category State
60
+ * @default Visible.YES
61
+ * @hidden
62
+ */
63
+ _visible = Visible.YES;
64
+ /**
65
+ * Internal Status state of the component
66
+ * @category State
67
+ * @default
68
+ * @hidden
69
+ */
70
+ _status = Status.UNPINNED;
71
+ /**
72
+ * on triggered when any event is triggered
73
+ * @category Events
74
+ * @hidden
75
+ */
76
+ _on = null;
77
+ /**
78
+ * onhide triggered when pin visibility changes to hidden
79
+ * @category Events
80
+ * @hidden
81
+ */
82
+ _onhide = null;
83
+ /**
84
+ * onshow triggered when pin visibility changes to visible
85
+ * @category Events
86
+ * @hidden
87
+ */
88
+ _onshow = null;
89
+ /**
90
+ * onpin triggered when pin status changes to pinned
91
+ * @category Events
92
+ * @hidden
93
+ */
94
+ _onpin = null;
95
+ /**
96
+ * onunpin triggered when pin state changes to unpinned
97
+ * @category Events
98
+ * @hidden
99
+ */
100
+ _onunpin = null;
101
+ constructor() {
102
+ super(configuration);
103
+ }
104
+ /**
105
+ * Get and Sets the visibility of the pin button
106
+ * @category State
107
+ */
108
+ get visible() {
109
+ return this.hasAttribute(Attribute.VISIBLE)
110
+ ? this.getAttribute(Attribute.VISIBLE)
111
+ : this._visible;
112
+ }
113
+ set visible(visible) {
114
+ visible = visible || Visible.YES;
115
+ if (this._visible !== visible) {
116
+ this._visible = visible;
117
+ visible == Visible.YES && this.removeAttribute(Attribute.VISIBLE);
118
+ visible == Visible.NO && this.setAttribute(Attribute.VISIBLE, visible);
119
+ visible == Visible.NO &&
120
+ this._dispatchEvent(Event.ON_HIDE, { detail: { visible } });
121
+ visible == Visible.YES &&
122
+ this._dispatchEvent(Event.ON_SHOW, { detail: { visible } });
123
+ }
124
+ }
125
+ /**
126
+ * Get and Sets the status of the pin button
127
+ * @category State
128
+ */
129
+ get status() {
130
+ return this.hasAttribute(Attribute.STATUS)
131
+ ? this.getAttribute(Attribute.STATUS)
132
+ : this._status;
133
+ }
134
+ set status(status) {
135
+ if (this._status !== status) {
136
+ this._status = status;
137
+ this.setAttribute(Attribute.STATUS, status);
138
+ status == Status.PINNED &&
139
+ this._dispatchEvent(Event.ON_PIN, { detail: { status } });
140
+ status == Status.UNPINNED &&
141
+ this._dispatchEvent(Event.ON_UNPIN, { detail: { status } });
142
+ }
143
+ }
144
+ /**
145
+ * Triggered on any event
146
+ * @event
147
+ * @category Events
148
+ */
149
+ set on(handler) {
150
+ Object
151
+ .values(Event)
152
+ .filter((event) => event !== Event.ON)
153
+ .forEach((event) => {
154
+ this._on && this.removeEventListener(event, this._on);
155
+ this._on = handler;
156
+ this._on && this.addEventListener(event, this._on);
157
+ });
158
+ }
159
+ /**
160
+ * Triggered via `.hide()`
161
+ * @event
162
+ * @category Events
163
+ */
164
+ set onhide(handler) {
165
+ this._onhide && this.removeEventListener(Event.ON_HIDE, this._onhide);
166
+ this._onhide = handler;
167
+ this._onhide && this.addEventListener(Event.ON_HIDE, this._onhide);
168
+ }
169
+ /**
170
+ * Triggered via `.show()`
171
+ * @event
172
+ * @category Events
173
+ */
174
+ set onshow(handler) {
175
+ this._onshow && this.removeEventListener(Event.ON_SHOW, this._onshow);
176
+ this._onshow = handler;
177
+ this._onshow && this.addEventListener(Event.ON_SHOW, this._onshow);
178
+ }
179
+ /**
180
+ * Triggered via `.pin()`
181
+ * @event
182
+ * @category Events
183
+ */
184
+ set onpin(handler) {
185
+ this._onpin && this.removeEventListener(Event.ON_PIN, this._onpin);
186
+ this._onpin = handler;
187
+ this._onpin && this.addEventListener(Event.ON_PIN, this._onpin);
188
+ }
189
+ /**
190
+ * Triggered via `.unpin()`
191
+ * @event
192
+ * @category Events
193
+ */
194
+ set onunpin(handler) {
195
+ this._onunpin && this.removeEventListener(Event.ON_UNPIN, this._onunpin);
196
+ this._onunpin = handler;
197
+ this._onunpin && this.addEventListener(Event.ON_UNPIN, this._onunpin);
198
+ }
199
+ /**
200
+ * Hide the pin button when it is visible
201
+ * @category Operations
202
+ */
203
+ hide = () => (this.visible = Visible.NO);
204
+ /**
205
+ * Show the pin button when it is hidden
206
+ * @category Operations
207
+ */
208
+ show = () => (this.visible = Visible.YES);
209
+ /**
210
+ * Pin the pin button when it is unpinned
211
+ * @category Operations
212
+ */
213
+ pin = () => (this.status = Status.PINNED);
214
+ /**
215
+ * Unpin the pin button when it is pinned
216
+ * @category Operations
217
+ */
218
+ unpin = () => (this.status = Status.UNPINNED);
219
+ /**
220
+ * Toggle the pin button between pinned and unpinned
221
+ * @category Operations
222
+ */
223
+ toggle = () => (this.status =
224
+ this.status === Status.PINNED ? Status.UNPINNED : Status.PINNED);
225
+ /**
226
+ * List operations to perform for selected attributes being observed in the DOM.
227
+ * @category Configuration
228
+ * @hidden
229
+ */
230
+ _attributeHandlers = {
231
+ [Attribute.VISIBLE]: (value) => (this.visible = value),
232
+ [Attribute.STATUS]: (value) => (this.status = value),
233
+ };
234
+ /**
235
+ * Initialize component attributes with default values
236
+ * @category Configuration
237
+ * @hidden
238
+ */
239
+ _initialize = () => this._initializeState();
240
+ /**
241
+ * Cache element references to improve performance
242
+ * @category Configuration
243
+ * @hidden
244
+ */
245
+ _cacheElements = () => this._cacheIcon();
246
+ /**
247
+ * Called by the connectedCallback prototypical method
248
+ * @category Configuration
249
+ * @hidden
250
+ */
251
+ _addEventListeners = () => this.elements.icon.addEventListener(Gesture.CLICK, this._handleClick);
252
+ /**
253
+ * Called by the disconnectedCallback prototypical method
254
+ * @category Configuration
255
+ * @hidden
256
+ */
257
+ _removeEventListeners = () => this.elements.icon.removeEventListener(Gesture.CLICK, this._handleClick);
258
+ /**
259
+ * Initialize component state with default values
260
+ * @category State
261
+ * @hidden
262
+ */
263
+ _initializeState = () => this.setAttribute(Attribute.STATUS, this._status);
264
+ /**
265
+ * Cache icon element reference to improve performance
266
+ * @category State
267
+ * @hidden
268
+ */
269
+ _cacheIcon = () => (this.elements.icon = this.root.querySelector(".icon"));
270
+ /**
271
+ * Handles the click event
272
+ * @category Gesture
273
+ * @hidden
274
+ */
275
+ _handleClick = (event) => this.toggle();
276
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * @module Component
3
+ */
4
+ export declare const Tag: "pin-button";
5
+ /**
6
+ * HTML Attributes available to set
7
+ * @category Metadata: State
8
+ * @enum
9
+ */
10
+ export declare const Attribute: {
11
+ readonly VISIBLE: "visible";
12
+ readonly STATUS: "status";
13
+ };
14
+ /**
15
+ * HTML Attributes available to set
16
+ * @category Metadata: State
17
+ */
18
+ export type Attributes = typeof Attribute;
19
+ /**
20
+ * HTML Attributes available to set
21
+ * @category Metadata: State
22
+ * @enum
23
+ */
24
+ export declare const State: {
25
+ readonly VISIBLE: "visible";
26
+ readonly STATUS: "status";
27
+ };
28
+ /**
29
+ * HTML Attributes available to set
30
+ * @category Metadata: State
31
+ */
32
+ export type States = (typeof State)[keyof typeof State];
33
+ /**
34
+ * Visible state used to show or hide the component
35
+ * @category Metadata: State
36
+ * @enum
37
+ */
38
+ export declare const Visible: {
39
+ readonly YES: "yes";
40
+ readonly NO: "no";
41
+ };
42
+ /**
43
+ * Visible state used to show or hide the component
44
+ * @category Metadata: State
45
+ */
46
+ export type Visibility = (typeof Visible)[keyof typeof Visible];
47
+ /**
48
+ * @category Metadata: State
49
+ * @enum
50
+ */
51
+ export declare const Status: {
52
+ readonly PINNED: "pinned";
53
+ readonly UNPINNED: "unpinned";
54
+ };
55
+ /**
56
+ * @category Metadata: State
57
+ */
58
+ export type Statuses = (typeof Status)[keyof typeof Status];
59
+ /**
60
+ * @category Metadata: Operations
61
+ * @enum
62
+ */
63
+ export declare const Operation: {
64
+ readonly HIDE: "hide";
65
+ readonly SHOW: "show";
66
+ readonly PIN: "pin";
67
+ readonly UNPIN: "unpin";
68
+ readonly TOGGLE: "toggle";
69
+ };
70
+ /**
71
+ * @category Metadata: Operations
72
+ */
73
+ export type Operations = (typeof Operation)[keyof typeof Operation];
74
+ /**
75
+ * @category Metadata: Events
76
+ * @enum
77
+ */
78
+ export declare const Event: {
79
+ readonly ON_HIDE: "onhide";
80
+ readonly ON_SHOW: "onshow";
81
+ readonly ON_PIN: "onpin";
82
+ readonly ON_UNPIN: "onunpin";
83
+ readonly ON: "on";
84
+ };
85
+ /**
86
+ * @category Metadata: Events
87
+ */
88
+ export type Events = (typeof Event)[keyof typeof Event];
89
+ /**
90
+ * @category Metadata: Gesture
91
+ * @enum
92
+ */
93
+ export declare const Gesture: {
94
+ readonly CLICK: "click";
95
+ };
96
+ /**
97
+ * @category Metadata: Gesture
98
+ */
99
+ export type Gestures = (typeof Gesture)[keyof typeof Gesture];
100
+ /**
101
+ * Event handler signature
102
+ * @hidden
103
+ */
104
+ export type Handler = (...args: any[]) => void;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @module Component
3
+ */
4
+ export const Tag = "pin-button";
5
+ /**
6
+ * HTML Attributes available to set
7
+ * @category Metadata: State
8
+ * @enum
9
+ */
10
+ export const Attribute = {
11
+ VISIBLE: "visible",
12
+ STATUS: "status",
13
+ };
14
+ /**
15
+ * HTML Attributes available to set
16
+ * @category Metadata: State
17
+ * @enum
18
+ */
19
+ export const State = {
20
+ ...Attribute,
21
+ };
22
+ /**
23
+ * Visible state used to show or hide the component
24
+ * @category Metadata: State
25
+ * @enum
26
+ */
27
+ export const Visible = {
28
+ YES: "yes",
29
+ NO: "no",
30
+ };
31
+ /**
32
+ * @category Metadata: State
33
+ * @enum
34
+ */
35
+ export const Status = {
36
+ PINNED: "pinned",
37
+ UNPINNED: "unpinned",
38
+ };
39
+ /**
40
+ * @category Metadata: Operations
41
+ * @enum
42
+ */
43
+ export const Operation = {
44
+ HIDE: "hide",
45
+ SHOW: "show",
46
+ PIN: "pin",
47
+ UNPIN: "unpin",
48
+ TOGGLE: "toggle",
49
+ };
50
+ /**
51
+ * @category Metadata: Events
52
+ * @enum
53
+ */
54
+ export const Event = {
55
+ ON_HIDE: "onhide",
56
+ ON_SHOW: "onshow",
57
+ ON_PIN: "onpin",
58
+ ON_UNPIN: "onunpin",
59
+ ON: "on",
60
+ };
61
+ /**
62
+ * @category Metadata: Gesture
63
+ * @enum
64
+ */
65
+ export const Gesture = {
66
+ CLICK: "click",
67
+ };