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,91 +0,0 @@
1
- // @ts-ignore
2
- import React from "react";
3
- import "./selected-section.js";
4
- export const SelectedSection = React.forwardRef((props, ref) => {
5
- const { label, "show-input": showInput, value, disabled, error, loading, selected: selectedSelected, children, onDelete, onClear, onChange, onInputChange, onFocus, ...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 && selectedSelected !== undefined) {
19
- if (el.getManager && el.getManager()) {
20
- el.getManager().setSelected(typeof selectedSelected === "string" ? JSON.parse(selectedSelected) : selectedSelected);
21
- }
22
- else {
23
- el.setAttribute("selected", typeof selectedSelected === "string" ? selectedSelected : JSON.stringify(selectedSelected));
24
- }
25
- }
26
- }, [selectedSelected]);
27
- React.useLayoutEffect(() => {
28
- const el = internalRef.current;
29
- if (el && el.getManager && el.getManager()) {
30
- const mgr = el.getManager();
31
- const sub = mgr.getSubscriber();
32
- if (sub) {
33
- const unbinds = [];
34
- if (onDelete) {
35
- unbinds.push(sub.bind("onDelete", (id) => onDelete(id)));
36
- }
37
- if (onClear) {
38
- unbinds.push(sub.bind("onClear", () => onClear()));
39
- }
40
- if (onChange) {
41
- unbinds.push(sub.bind("onChange", (s) => onChange(s)));
42
- }
43
- if (onInputChange) {
44
- unbinds.push(sub.bind("onInputChange", (e, previousValue) => onInputChange({
45
- originalEvent: e,
46
- value: e.target.value,
47
- key: e.key || "",
48
- previousValue,
49
- })));
50
- }
51
- if (onFocus) {
52
- unbinds.push(sub.bind("onFocus", (e) => onFocus({ originalEvent: e })));
53
- }
54
- return () => {
55
- unbinds.forEach((u) => u());
56
- };
57
- }
58
- }
59
- }, [onDelete, onClear, onChange, onInputChange, onFocus]);
60
- const wcProps = { ...rest, ref: setRef };
61
- if (label !== undefined)
62
- wcProps.label = label;
63
- if (value !== undefined)
64
- wcProps.value = value;
65
- if (String(showInput) === "true") {
66
- wcProps["show-input"] = "true";
67
- }
68
- else {
69
- delete wcProps["show-input"];
70
- }
71
- if (String(disabled) === "true") {
72
- wcProps.disabled = "true";
73
- }
74
- else {
75
- delete wcProps.disabled;
76
- }
77
- if (String(error) === "true") {
78
- wcProps.error = "true";
79
- }
80
- else {
81
- delete wcProps.error;
82
- }
83
- if (String(loading) === "true") {
84
- wcProps.loading = "true";
85
- }
86
- else {
87
- delete wcProps.loading;
88
- }
89
- return React.createElement("selected-section", wcProps, children);
90
- });
91
- export default SelectedSection;
@@ -1,207 +0,0 @@
1
- import { SelectedSectionManager } from "./SelectedSectionManager.js";
2
- /**
3
- * Injects CSS into the Shadow DOM.
4
- * Priority:
5
- * 1. SelectedSection.cssText (Bundler string injection)
6
- * 2. <meta name="select-component" content="/path1.css, /path2.css"> (Global HTML declaration in main document)
7
- * 3. SelectedSection.defaultCssUrls (Global JS property)
8
- *
9
- * Example of Global HTML Declaration in the main document <head>:
10
- * <head>
11
- * <meta name="select-component" content="SelectedSectionManager.css">
12
- * </head>
13
- */
14
- export class SelectedSection extends HTMLElement {
15
- _manager = null;
16
- _options = {};
17
- _mountPoint;
18
- _stylesInjected = false;
19
- // 1. For Bundlers: Assign CSS string directly (e.g. import css from './style.css?raw')
20
- static cssText = "";
21
- // 2. For Vanilla JS: Default URLs (Vite/Webpack5 will also process import.meta.url)
22
- static defaultCssUrls = [];
23
- static get observedAttributes() {
24
- return ["label", "show-input", "value", "disabled", "error", "loading", "selected"];
25
- }
26
- constructor() {
27
- super();
28
- this.attachShadow({ mode: "open" });
29
- this.shadowRoot.innerHTML = `<style></style><div></div>`;
30
- this._mountPoint = this.shadowRoot.querySelector("div");
31
- }
32
- connectedCallback() {
33
- this._injectStyles();
34
- if (this._manager)
35
- return;
36
- this._options = {
37
- label: this.getAttribute("label") || "",
38
- showInput: this.hasAttribute("show-input"),
39
- value: this.getAttribute("value") || "",
40
- disabled: this.hasAttribute("disabled"),
41
- error: this.hasAttribute("error"),
42
- loading: this.hasAttribute("loading"),
43
- selected: this._parseJSON(this.getAttribute("selected")) ?? [],
44
- };
45
- this._manager = new SelectedSectionManager(this._mountPoint, this._options);
46
- }
47
- disconnectedCallback() {
48
- this._manager?.destroy();
49
- this._manager = null;
50
- }
51
- attributeChangedCallback(name, _oldValue, newValue) {
52
- if (!this._manager)
53
- return;
54
- const isTrue = this.hasAttribute(name);
55
- switch (name) {
56
- case "label":
57
- this._manager.setLabel(newValue);
58
- break;
59
- case "show-input":
60
- this._manager.setShowInput(isTrue);
61
- break;
62
- case "value":
63
- this._manager.setValue(newValue);
64
- break;
65
- case "disabled":
66
- this._manager.setDisabled(isTrue);
67
- break;
68
- case "error":
69
- this._manager.setError(isTrue);
70
- break;
71
- case "loading":
72
- this._manager.setLoading(isTrue);
73
- break;
74
- case "selected": {
75
- const parsed = this._parseJSON(newValue);
76
- if (parsed !== undefined) {
77
- this._manager.setSelected(parsed);
78
- }
79
- break;
80
- }
81
- }
82
- }
83
- _injectStyles() {
84
- if (this._stylesInjected)
85
- return;
86
- this._stylesInjected = true;
87
- const style = document.createElement("style");
88
- // Scenario A: Bundler injected raw CSS string directly
89
- if (SelectedSection.cssText) {
90
- style.textContent = SelectedSection.cssText;
91
- }
92
- // Scenario B: Load from URLs (Global Meta Tag > Default Static Property)
93
- else {
94
- let urls = [];
95
- const metaTag = document.querySelector('meta[name="select-component"]');
96
- if (metaTag && metaTag.getAttribute("content")) {
97
- urls = metaTag
98
- .getAttribute("content")
99
- .split(",")
100
- .map((s) => s.trim());
101
- }
102
- else {
103
- urls = SelectedSection.defaultCssUrls;
104
- }
105
- urls.forEach((url) => {
106
- if (!url)
107
- return;
108
- style.textContent += `@import url("${url}");\n`;
109
- });
110
- }
111
- // Remove existing injected CSS if updating dynamically
112
- const existingStyle = this.shadowRoot.querySelector("style");
113
- if (existingStyle) {
114
- existingStyle.remove();
115
- }
116
- this.shadowRoot.appendChild(style);
117
- }
118
- // Proxied methods
119
- setSelected(list) {
120
- this._manager?.setSelected(list);
121
- }
122
- setValue(value) {
123
- this._manager?.setValue(value);
124
- }
125
- clearSearch(triggerOnChange = true) {
126
- this._manager?.clearSearch(triggerOnChange);
127
- }
128
- setError(state) {
129
- this.toggleAttribute("error", state);
130
- }
131
- setDisabled(state) {
132
- this.toggleAttribute("disabled", state);
133
- }
134
- setLoading(state) {
135
- this.toggleAttribute("loading", state);
136
- }
137
- setLabel(text) {
138
- this.setAttribute("label", text);
139
- }
140
- setShowInput(state) {
141
- this.toggleAttribute("show-input", state);
142
- }
143
- setRenderItem(renderer) {
144
- this._manager?.setRenderItem(renderer);
145
- }
146
- setRenderList(renderer) {
147
- this._manager?.setRenderList(renderer);
148
- }
149
- render() {
150
- this._manager?.render();
151
- }
152
- // Getters and setters for properties
153
- get selected() {
154
- return this._manager?.getSelected() || [];
155
- }
156
- set selected(val) {
157
- this.setSelected(val);
158
- }
159
- get value() {
160
- return this._manager?.propInputElement?.value || "";
161
- }
162
- set value(val) {
163
- this.setValue(val);
164
- }
165
- get label() {
166
- return this.getAttribute("label") || "";
167
- }
168
- set label(val) {
169
- this.setLabel(val);
170
- }
171
- get error() {
172
- return this.hasAttribute("error");
173
- }
174
- set error(val) {
175
- this.setError(val);
176
- }
177
- get disabled() {
178
- return this.hasAttribute("disabled");
179
- }
180
- set disabled(val) {
181
- this.setDisabled(val);
182
- }
183
- get loading() {
184
- return this.hasAttribute("loading");
185
- }
186
- set loading(val) {
187
- this.setLoading(val);
188
- }
189
- setFocus() {
190
- this._manager?.setFocus();
191
- }
192
- getManager() {
193
- return this._manager;
194
- }
195
- _parseJSON(val) {
196
- if (!val)
197
- return undefined;
198
- try {
199
- return JSON.parse(val);
200
- }
201
- catch (e) {
202
- console.error(`SelectedSection: failed to parse JSON:`, val, e);
203
- return undefined;
204
- }
205
- }
206
- }
207
- customElements.define("selected-section", SelectedSection);
@@ -1,17 +0,0 @@
1
- export function clickOutside(targets, callback) {
2
- const targetList = Array.isArray(targets) ? targets : [targets];
3
- const handler = (e) => {
4
- const node = e.target;
5
- const isInside = targetList.some((target) => target && target.contains(node));
6
- if (!isInside) {
7
- callback(e);
8
- }
9
- };
10
- // Use capturing phase so we don't miss events if some child stops propagation
11
- document.addEventListener("click", handler, true);
12
- document.addEventListener("touchstart", handler, { capture: true, passive: true });
13
- return function unbind() {
14
- document.removeEventListener("click", handler, true);
15
- document.removeEventListener("touchstart", handler, true);
16
- };
17
- }
@@ -1,13 +0,0 @@
1
- --- node_modules/playwright-core/lib/coreBundle.js 2026-05-23 03:29:43
2
- +++ diff/coreBundle.js 2026-05-23 04:08:12
3
- @@ -46685,8 +46685,8 @@
4
- const recorderPlaywright = createPlaywright2({ sdkLanguage: "javascript", isInternalPlaywright: true });
5
- const { context: appContext, page } = await launchApp(recorderPlaywright.chromium, {
6
- sdkLanguage,
7
- - windowSize: { width: 600, height: 600 },
8
- - windowPosition: { x: 1020, y: 10 },
9
- + windowSize: { width: 1000, height: 1200 },
10
- + windowPosition: { x: 1320, y: 5 },
11
- persistentContextOptions: {
12
- noDefaultViewport: true,
13
- headless: !!process.env.PWTEST_CLI_HEADLESS || isUnderTest() && !headed,
@@ -1,13 +0,0 @@
1
- --- node_modules/playwright-core/lib/server/recorder/recorderApp.js 2026-05-21 17:28:58
2
- +++ diff/recorderApp.js 2026-05-21 17:34:13
3
- @@ -186,8 +186,8 @@
4
- const recorderPlaywright = require("../playwright").createPlaywright({ sdkLanguage: "javascript", isInternalPlaywright: true });
5
- const { context: appContext, page } = await (0, import_launchApp2.launchApp)(recorderPlaywright.chromium, {
6
- sdkLanguage,
7
- - windowSize: { width: 600, height: 600 },
8
- - windowPosition: { x: 1020, y: 10 },
9
- + windowSize: { width: 1000, height: 1200 },
10
- + windowPosition: { x: 1320, y: 5 },
11
- persistentContextOptions: {
12
- noDefaultViewport: true,
13
- headless: !!process.env.PWTEST_CLI_HEADLESS || (0, import_debug.isUnderTest)() && !headed,
package/madooei.tar.gz DELETED
Binary file
package/release.config.js DELETED
@@ -1,3 +0,0 @@
1
- export default {
2
- preset: "conventionalcommits",
3
- };
package/test/lib.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { type Page } from "@playwright/test";
2
- export declare function softNavigate(page: Page, url: string): Promise<void>;
3
- export declare function querySelector(page: Page, selector: string): Promise<import("playwright-core").Locator>;
4
- export declare function clickSelector(page: Page, selector: string): Promise<void>;
5
- export declare function prepare(page: Page, link: string): Promise<void>;
6
- export declare function compareSelectedItems(page: Page, selector: string, data: string | any[], decodeJson?: boolean): Promise<void>;
package/test/lib.js DELETED
@@ -1,30 +0,0 @@
1
- import { expect } from "@playwright/test";
2
- export async function softNavigate(page, url) {
3
- await page.evaluate((url) => {
4
- window.history.pushState({}, "", url);
5
- window.dispatchEvent(new PopStateEvent("popstate", { state: {} }));
6
- }, url);
7
- }
8
- export async function querySelector(page, selector) {
9
- const linkLocator = page.locator(selector);
10
- await expect(linkLocator).toHaveCount(1);
11
- return linkLocator;
12
- }
13
- export async function clickSelector(page, selector) {
14
- const selectorLocator = await querySelector(page, selector);
15
- await selectorLocator.click();
16
- }
17
- export async function prepare(page, link) {
18
- await page.goto("/vite-project/dist/");
19
- const linkLocator = await querySelector(page, link);
20
- await expect(linkLocator).toHaveText("CompositeSelect Manager Demo");
21
- }
22
- export async function compareSelectedItems(page, selector, data, decodeJson = true) {
23
- const selectedItems = await querySelector(page, selector);
24
- // then extract innerHTML and parse as JSON
25
- let content = await selectedItems.innerHTML();
26
- if (decodeJson) {
27
- content = JSON.parse(content);
28
- }
29
- expect(content).toEqual(data);
30
- }