@forcecalendar/interface 1.0.27 → 1.0.29

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.
@@ -10,109 +10,111 @@
10
10
  */
11
11
 
12
12
  export class BaseComponent extends HTMLElement {
13
- constructor() {
14
- super();
15
- this.attachShadow({ mode: 'open' });
16
- this._listeners = [];
17
- this._state = null;
18
- this._props = new Map();
19
- this._initialized = false;
20
- }
21
-
22
- // Lifecycle methods
23
- connectedCallback() {
24
- if (!this._initialized) {
25
- this.initialize();
26
- this._initialized = true;
27
- }
28
- this.mount();
29
- }
30
-
31
- disconnectedCallback() {
32
- this.unmount();
33
- this.cleanup();
34
- }
35
-
36
- // To be overridden by child classes
37
- initialize() {
38
- // Setup component-specific initialization
39
- }
40
-
41
- mount() {
42
- // Component mounted to DOM
43
- this.render();
44
- }
45
-
46
- unmount() {
47
- // Component removed from DOM
48
- }
49
-
50
- cleanup() {
51
- // Clean up event listeners
52
- this._listeners.forEach(({ element, event, handler }) => {
53
- element.removeEventListener(event, handler);
54
- });
55
- this._listeners = [];
56
- }
57
-
58
- // State management
59
- setState(newState) {
60
- const oldState = this._state;
61
- this._state = { ...this._state, ...newState };
62
- this.stateChanged(oldState, this._state);
63
- this.render();
64
- }
65
-
66
- getState() {
67
- return this._state;
68
- }
69
-
70
- stateChanged(oldState, newState) {
71
- // Override in child classes to handle state changes
72
- }
73
-
74
- // Props management
75
- setProp(key, value) {
76
- const oldValue = this._props.get(key);
77
- this._props.set(key, value);
78
- this.propChanged(key, oldValue, value);
79
- }
80
-
81
- getProp(key) {
82
- return this._props.get(key);
83
- }
84
-
85
- propChanged(key, oldValue, newValue) {
86
- // Override in child classes to handle prop changes
87
- }
88
-
89
- // Event handling
90
- addListener(element, event, handler) {
91
- if (!element || !event || !handler) {
92
- console.warn('addListener called with invalid parameters', { element, event, handler });
93
- return;
94
- }
95
- const boundHandler = handler.bind(this);
96
- element.addEventListener(event, boundHandler);
97
- this._listeners.push({ element, event, handler: boundHandler });
98
- }
99
-
100
- emit(eventName, detail = {}) {
101
- this.dispatchEvent(new CustomEvent(eventName, {
102
- detail,
103
- bubbles: true,
104
- composed: true
105
- }));
106
- }
107
-
108
- // Style management
109
- getStyles() {
110
- // Override in child classes to provide component styles
111
- return '';
112
- }
113
-
114
- getBaseStyles() {
115
- return `
13
+ constructor() {
14
+ super();
15
+ this.attachShadow({ mode: 'open' });
16
+ this._listeners = [];
17
+ this._state = null;
18
+ this._props = new Map();
19
+ this._initialized = false;
20
+ }
21
+
22
+ // Lifecycle methods
23
+ connectedCallback() {
24
+ if (!this._initialized) {
25
+ this.initialize();
26
+ this._initialized = true;
27
+ }
28
+ this.mount();
29
+ }
30
+
31
+ disconnectedCallback() {
32
+ this.unmount();
33
+ this.cleanup();
34
+ }
35
+
36
+ // To be overridden by child classes
37
+ initialize() {
38
+ // Setup component-specific initialization
39
+ }
40
+
41
+ mount() {
42
+ // Component mounted to DOM
43
+ this.render();
44
+ }
45
+
46
+ unmount() {
47
+ // Component removed from DOM
48
+ }
49
+
50
+ cleanup() {
51
+ // Clean up event listeners
52
+ this._listeners.forEach(({ element, event, handler }) => {
53
+ element.removeEventListener(event, handler);
54
+ });
55
+ this._listeners = [];
56
+ }
57
+
58
+ // State management
59
+ setState(newState) {
60
+ const oldState = this._state;
61
+ this._state = { ...this._state, ...newState };
62
+ this.stateChanged(oldState, this._state);
63
+ this.render();
64
+ }
65
+
66
+ getState() {
67
+ return this._state;
68
+ }
69
+
70
+ stateChanged(_oldState, _newState) {
71
+ // Override in child classes to handle state changes
72
+ }
73
+
74
+ // Props management
75
+ setProp(key, value) {
76
+ const oldValue = this._props.get(key);
77
+ this._props.set(key, value);
78
+ this.propChanged(key, oldValue, value);
79
+ }
80
+
81
+ getProp(key) {
82
+ return this._props.get(key);
83
+ }
84
+
85
+ propChanged(_key, _oldValue, _newValue) {
86
+ // Override in child classes to handle prop changes
87
+ }
88
+
89
+ // Event handling
90
+ addListener(element, event, handler) {
91
+ if (!element || !event || !handler) {
92
+ console.warn('addListener called with invalid parameters', { element, event, handler });
93
+ return;
94
+ }
95
+ const boundHandler = handler.bind(this);
96
+ element.addEventListener(event, boundHandler);
97
+ this._listeners.push({ element, event, handler: boundHandler });
98
+ }
99
+
100
+ emit(eventName, detail = {}) {
101
+ this.dispatchEvent(
102
+ new CustomEvent(eventName, {
103
+ detail,
104
+ bubbles: true,
105
+ composed: true
106
+ })
107
+ );
108
+ }
109
+
110
+ // Style management
111
+ getStyles() {
112
+ // Override in child classes to provide component styles
113
+ return '';
114
+ }
115
+
116
+ getBaseStyles() {
117
+ return `
116
118
  :host {
117
119
  display: block;
118
120
  box-sizing: border-box;
@@ -122,52 +124,52 @@ export class BaseComponent extends HTMLElement {
122
124
  box-sizing: inherit;
123
125
  }
124
126
  `;
125
- }
127
+ }
126
128
 
127
- // Template rendering
128
- render() {
129
- // Clean up existing listeners before replacing DOM
130
- this.cleanup();
129
+ // Template rendering
130
+ render() {
131
+ // Clean up existing listeners before replacing DOM
132
+ this.cleanup();
131
133
 
132
- const styles = `
134
+ const styles = `
133
135
  <style>
134
136
  ${this.getBaseStyles()}
135
137
  ${this.getStyles()}
136
138
  </style>
137
139
  `;
138
140
 
139
- const template = this.template();
140
- this.shadowRoot.innerHTML = styles + template;
141
- this.afterRender();
142
- }
143
-
144
- template() {
145
- // Override in child classes to provide component template
146
- return '';
147
- }
148
-
149
- afterRender() {
150
- // Override in child classes for post-render operations
151
- }
152
-
153
- // Utility methods
154
- $(selector) {
155
- return this.shadowRoot.querySelector(selector);
156
- }
157
-
158
- $$(selector) {
159
- return this.shadowRoot.querySelectorAll(selector);
160
- }
161
-
162
- // Attribute observation
163
- static get observedAttributes() {
164
- return [];
165
- }
166
-
167
- attributeChangedCallback(name, oldValue, newValue) {
168
- this.setProp(name, newValue);
169
- if (this._initialized) {
170
- this.render();
171
- }
172
- }
173
- }
141
+ const template = this.template();
142
+ this.shadowRoot.innerHTML = styles + template;
143
+ this.afterRender();
144
+ }
145
+
146
+ template() {
147
+ // Override in child classes to provide component template
148
+ return '';
149
+ }
150
+
151
+ afterRender() {
152
+ // Override in child classes for post-render operations
153
+ }
154
+
155
+ // Utility methods
156
+ $(selector) {
157
+ return this.shadowRoot.querySelector(selector);
158
+ }
159
+
160
+ $$(selector) {
161
+ return this.shadowRoot.querySelectorAll(selector);
162
+ }
163
+
164
+ // Attribute observation
165
+ static get observedAttributes() {
166
+ return [];
167
+ }
168
+
169
+ attributeChangedCallback(name, oldValue, newValue) {
170
+ this.setProp(name, newValue);
171
+ if (this._initialized) {
172
+ this.render();
173
+ }
174
+ }
175
+ }