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