composite-select 1.0.3 → 1.0.5

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.
@@ -1,189 +0,0 @@
1
- // @ts-ignore
2
- import React from "react";
3
- import "./composite-select.js";
4
- export const CompositeSelect = React.forwardRef((props, ref) => {
5
- const { "selected-selected": selectedSelected, "selected-show-input": selectedShowInput, "selected-value": selectedValue, "selected-label": selectedLabel, "selected-disabled": selectedDisabled, "selected-error": selectedError, "selected-loading": selectedLoading, "selected-show-delete": selectedShowDelete, "selected-onDelete": selectedOnDelete, "selected-onClear": selectedOnClear, "selected-onInputChange": selectedOnChangeValue, "selected-onFocus": selectedOnFocus, "selected-onChange": selectedOnChange, "selected-onComponentChange": selectedOnSelectedItemsChanged, "options-options": optionsOptions, "options-loading": optionsLoading, "options-value": optionsValue, "options-label": optionsLabel, "options-disabled": optionsDisabled, "options-max-height": optionsMaxHeight, "options-show-footer": optionsShowFooter, "options-show-filter": optionsFilter, "options-onItemPick": optionsOnItemPick, "options-onInputChange": optionsOnInputChange, "options-onCancel": optionsOnCancel, "options-onOk": optionsOnOk, "options-onHighlightChange": optionsOnHighlightChange, "options-onClear": optionsOnClear, "options-onComponentChange": optionsOnOptionsChanged, "container-position": containerPosition, "container-offset": containerOffset, "container-onClose": containerOnClose, children, ...rest } = props;
6
- const internalRef = React.useRef(null);
7
- const setRef = React.useCallback((node) => {
8
- internalRef.current = node;
9
- if (typeof ref === "function") {
10
- ref(node);
11
- }
12
- else if (ref) {
13
- ref.current = node;
14
- }
15
- }, [ref]);
16
- React.useLayoutEffect(() => {
17
- const el = internalRef.current;
18
- if (el && el.getManager && el.getManager()) {
19
- const mgr = el.getManager();
20
- const unbinds = [];
21
- // SelectedSection events
22
- const selSub = mgr.selected.getSubscriber();
23
- if (selSub) {
24
- if (selectedOnDelete) {
25
- unbinds.push(selSub.bind("onDelete", (id) => selectedOnDelete(id)));
26
- }
27
- if (selectedOnClear) {
28
- unbinds.push(selSub.bind("onClear", () => selectedOnClear()));
29
- }
30
- if (selectedOnChangeValue) {
31
- unbinds.push(selSub.bind("onInputChange", (e, previousValue) => selectedOnChangeValue({
32
- originalEvent: e,
33
- value: e.target.value,
34
- key: e.key || "",
35
- previousValue,
36
- })));
37
- }
38
- if (selectedOnFocus) {
39
- unbinds.push(selSub.bind("onFocus", (e) => selectedOnFocus({ originalEvent: e })));
40
- }
41
- if (selectedOnChange) {
42
- unbinds.push(selSub.bind("onChange", (selected) => selectedOnChange(selected)));
43
- }
44
- if (selectedOnSelectedItemsChanged) {
45
- unbinds.push(selSub.bind("onComponentChange", (options, reason) => selectedOnSelectedItemsChanged(options, reason)));
46
- }
47
- }
48
- // OptionsSection events
49
- const optSub = mgr.options.getSubscriber();
50
- if (optSub) {
51
- if (optionsOnItemPick) {
52
- unbinds.push(optSub.bind("onItemPick", (item) => optionsOnItemPick(item)));
53
- }
54
- if (optionsOnInputChange) {
55
- unbinds.push(optSub.bind("onInputChange", (e, previousValue) => optionsOnInputChange({
56
- originalEvent: e,
57
- value: e.target.value,
58
- previousValue,
59
- })));
60
- }
61
- if (optionsOnCancel) {
62
- unbinds.push(optSub.bind("onCancel", () => optionsOnCancel()));
63
- }
64
- if (optionsOnOk) {
65
- unbinds.push(optSub.bind("onOk", () => optionsOnOk()));
66
- }
67
- if (optionsOnHighlightChange) {
68
- unbinds.push(optSub.bind("onHighlightChange", (id) => optionsOnHighlightChange(id)));
69
- }
70
- if (optionsOnClear) {
71
- unbinds.push(optSub.bind("onClear", () => optionsOnClear()));
72
- }
73
- if (optionsOnOptionsChanged) {
74
- unbinds.push(optSub.bind("onComponentChange", (options, reason) => optionsOnOptionsChanged(options, reason)));
75
- }
76
- }
77
- // Container events
78
- const conSub = mgr.container.getSubscriber();
79
- if (conSub) {
80
- if (containerOnClose) {
81
- unbinds.push(conSub.bind("onClose", () => containerOnClose()));
82
- }
83
- }
84
- return () => {
85
- unbinds.forEach((u) => u());
86
- };
87
- }
88
- }, [
89
- selectedOnDelete,
90
- selectedOnClear,
91
- selectedOnChangeValue,
92
- selectedOnFocus,
93
- selectedOnChange,
94
- selectedOnSelectedItemsChanged,
95
- optionsOnItemPick,
96
- optionsOnInputChange,
97
- optionsOnCancel,
98
- optionsOnOk,
99
- optionsOnHighlightChange,
100
- optionsOnClear,
101
- optionsOnOptionsChanged,
102
- containerOnClose,
103
- ]);
104
- React.useLayoutEffect(() => {
105
- const el = internalRef.current;
106
- if (el && el.getManager && el.getManager()) {
107
- if (selectedSelected !== undefined) {
108
- el.getManager().selected.setSelected(typeof selectedSelected === "string" ? JSON.parse(selectedSelected) : selectedSelected);
109
- }
110
- if (optionsOptions !== undefined) {
111
- el.getManager().options.setOptions(typeof optionsOptions === "string" ? JSON.parse(optionsOptions) : optionsOptions);
112
- }
113
- }
114
- }, [selectedSelected, optionsOptions]);
115
- const wcProps = { ...rest, ref: setRef };
116
- // Map selected-* attributes
117
- if (String(selectedShowInput) === "true") {
118
- wcProps["selected-show-input"] = "true";
119
- }
120
- else {
121
- delete wcProps["selected-show-input"];
122
- }
123
- if (selectedValue !== undefined)
124
- wcProps["selected-value"] = selectedValue;
125
- if (selectedLabel !== undefined)
126
- wcProps["selected-label"] = selectedLabel;
127
- if (String(selectedDisabled) === "true") {
128
- wcProps["selected-disabled"] = "true";
129
- }
130
- else {
131
- delete wcProps["selected-disabled"];
132
- }
133
- if (String(selectedError) === "true") {
134
- wcProps["selected-error"] = "true";
135
- }
136
- else {
137
- delete wcProps["selected-error"];
138
- }
139
- if (String(selectedLoading) === "true") {
140
- wcProps["selected-loading"] = "true";
141
- }
142
- else {
143
- delete wcProps["selected-loading"];
144
- }
145
- if (String(selectedShowDelete) === "true") {
146
- wcProps["selected-show-delete"] = "true";
147
- }
148
- else {
149
- delete wcProps["selected-show-delete"];
150
- }
151
- // Map options-* attributes
152
- if (String(optionsLoading) === "true") {
153
- wcProps["options-loading"] = "true";
154
- }
155
- else {
156
- delete wcProps["options-loading"];
157
- }
158
- if (optionsValue !== undefined)
159
- wcProps["options-value"] = optionsValue;
160
- if (optionsLabel !== undefined)
161
- wcProps["options-label"] = optionsLabel;
162
- if (String(optionsDisabled) === "true") {
163
- wcProps["options-disabled"] = "true";
164
- }
165
- else {
166
- delete wcProps["options-disabled"];
167
- }
168
- if (optionsMaxHeight !== undefined)
169
- wcProps["options-max-height"] = optionsMaxHeight;
170
- if (String(optionsShowFooter) === "true") {
171
- wcProps["options-show-footer"] = "true";
172
- }
173
- else {
174
- delete wcProps["options-show-footer"];
175
- }
176
- if (String(optionsFilter) === "true") {
177
- wcProps["options-show-filter"] = "true";
178
- }
179
- else {
180
- delete wcProps["options-show-filter"];
181
- }
182
- // Map container-* attributes
183
- if (containerPosition !== undefined)
184
- wcProps["container-position"] = containerPosition;
185
- if (containerOffset !== undefined)
186
- wcProps["container-offset"] = containerOffset;
187
- return React.createElement("composite-select", wcProps, children);
188
- });
189
- export default CompositeSelect;
@@ -1,76 +0,0 @@
1
- import createSubscriber from "../createSubscriber.js";
2
- export class ContainerManager {
3
- parent;
4
- target;
5
- popover;
6
- currentPosition = "cover-bottom";
7
- propOptions;
8
- _subscriber = createSubscriber();
9
- constructor(parent, options = {}) {
10
- this.parent = parent;
11
- this.propOptions = {
12
- ...options,
13
- };
14
- this.target = document.createElement("div");
15
- this.popover = document.createElement("div");
16
- this.popover.setAttribute("popover", "manual");
17
- this.popover.setAttribute("data-popover", "");
18
- this.popover.style.width = "anchor-size(width)";
19
- this.popover.style.boxSizing = "border-box";
20
- this.popover.style.border = "none";
21
- this.setPosition(this.currentPosition);
22
- this.setOffset("0px");
23
- this.parent.appendChild(this.target);
24
- this.parent.appendChild(this.popover);
25
- this.popover.addEventListener("beforetoggle", (event) => {
26
- if (event.newState === "closed") {
27
- if (this.propOptions.onClose) {
28
- this.propOptions.onClose();
29
- }
30
- this._subscriber.trigger("onClose");
31
- }
32
- });
33
- }
34
- getSubscriber() {
35
- return this._subscriber;
36
- }
37
- show() {
38
- this.popover.showPopover({ source: this.target });
39
- }
40
- hide() {
41
- this.popover.hidePopover();
42
- }
43
- getParent() {
44
- return this.parent;
45
- }
46
- getTarget() {
47
- return this.target;
48
- }
49
- getPopover() {
50
- return this.popover;
51
- }
52
- getPosition() {
53
- return this.currentPosition;
54
- }
55
- setPosition(position) {
56
- if (this.currentPosition) {
57
- this.popover.classList.remove(this.currentPosition);
58
- }
59
- this.currentPosition = position;
60
- if (this.currentPosition) {
61
- this.popover.classList.add(this.currentPosition);
62
- }
63
- }
64
- setOffset(offset) {
65
- this.popover.style.setProperty("--popover-offset", offset);
66
- }
67
- destroy() {
68
- if (this.target && this.target.parentNode) {
69
- this.target.parentNode.removeChild(this.target);
70
- }
71
- if (this.popover && this.popover.parentNode) {
72
- this.popover.parentNode.removeChild(this.popover);
73
- }
74
- this._subscriber.destroy();
75
- }
76
- }