@gitbook/react-openapi 1.5.1 → 1.5.2
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/CHANGELOG.md +9 -0
- package/dist/InteractiveSection.js +59 -0
- package/dist/Markdown.js +10 -0
- package/dist/OpenAPICodeSample.js +219 -0
- package/dist/OpenAPICodeSampleInteractive.js +66 -0
- package/dist/OpenAPICodeSampleSelector.js +45 -0
- package/dist/OpenAPICopyButton.js +39 -0
- package/dist/OpenAPIDisclosure.js +30 -0
- package/dist/OpenAPIDisclosureGroup.js +75 -0
- package/dist/OpenAPIExample.js +41 -0
- package/dist/OpenAPIMediaType.js +58 -0
- package/dist/OpenAPIOperation.d.ts +15 -0
- package/dist/OpenAPIOperation.js +30 -0
- package/dist/OpenAPIOperationContext.d.ts +20 -0
- package/dist/OpenAPIOperationContext.js +30 -0
- package/dist/OpenAPIPath.js +51 -0
- package/dist/OpenAPIPrefillContextProvider.d.ts +26 -0
- package/dist/OpenAPIPrefillContextProvider.js +25 -0
- package/dist/OpenAPIRequestBody.js +28 -0
- package/dist/OpenAPIRequestBodyHeaderType.js +23 -0
- package/dist/OpenAPIResponse.js +39 -0
- package/dist/OpenAPIResponseExample.js +75 -0
- package/dist/OpenAPIResponseExampleContent.js +61 -0
- package/dist/OpenAPIResponses.js +61 -0
- package/dist/OpenAPISchema.js +373 -0
- package/dist/OpenAPISchemaName.js +45 -0
- package/dist/OpenAPISchemaServer.js +13 -0
- package/dist/OpenAPISecurities.js +124 -0
- package/dist/OpenAPISelect.js +45 -0
- package/dist/OpenAPISpec.js +73 -0
- package/dist/OpenAPIWebhook.d.ts +15 -0
- package/dist/OpenAPIWebhook.js +28 -0
- package/dist/OpenAPIWebhookExample.js +40 -0
- package/dist/ScalarApiButton.js +87 -0
- package/dist/StaticSection.js +37 -0
- package/dist/code-samples.js +275 -0
- package/dist/common/OpenAPIColumnSpec.js +23 -0
- package/dist/common/OpenAPIOperationDescription.js +18 -0
- package/dist/common/OpenAPIStability.js +17 -0
- package/dist/common/OpenAPISummary.js +27 -0
- package/dist/contentTypeChecks.js +34 -0
- package/dist/context.d.ts +71 -0
- package/dist/context.js +29 -0
- package/dist/decycle.js +41 -0
- package/dist/dereference.js +24 -0
- package/dist/generateSchemaExample.js +198 -0
- package/dist/getDisclosureLabel.js +17 -0
- package/dist/getOrCreateStoreByKey.js +22 -0
- package/dist/index.d.ts +11 -662
- package/dist/index.js +9 -3871
- package/dist/json2xml.js +12 -0
- package/dist/resolveOpenAPIOperation.d.ts +15 -0
- package/dist/resolveOpenAPIOperation.js +102 -0
- package/dist/resolveOpenAPIWebhook.d.ts +15 -0
- package/dist/resolveOpenAPIWebhook.js +52 -0
- package/dist/schemas/OpenAPISchemaItem.js +26 -0
- package/dist/schemas/OpenAPISchemas.d.ts +19 -0
- package/dist/schemas/OpenAPISchemas.js +57 -0
- package/dist/schemas/resolveOpenAPISchemas.d.ts +15 -0
- package/dist/schemas/resolveOpenAPISchemas.js +17 -0
- package/dist/stringifyOpenAPI.js +14 -0
- package/dist/translate.js +43 -0
- package/dist/translations/de.js +48 -0
- package/dist/translations/en.d.ts +47 -0
- package/dist/translations/en.js +48 -0
- package/dist/translations/es.js +48 -0
- package/dist/translations/fr.js +48 -0
- package/dist/translations/index.d.ts +408 -0
- package/dist/translations/index.js +31 -0
- package/dist/translations/ja.js +48 -0
- package/dist/translations/nl.js +48 -0
- package/dist/translations/no.js +48 -0
- package/dist/translations/pt-br.js +48 -0
- package/dist/translations/types.d.ts +7 -0
- package/dist/translations/zh.js +48 -0
- package/dist/types.d.ts +37 -0
- package/dist/util/example.js +84 -0
- package/dist/util/server.js +38 -0
- package/dist/util/tryit-prefill.js +143 -0
- package/dist/utils.js +163 -0
- package/package.json +10 -7
package/dist/context.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { translations } from "./translations/index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/context.ts
|
|
4
|
+
/**
|
|
5
|
+
* Resolve OpenAPI context from the input.
|
|
6
|
+
*/
|
|
7
|
+
function resolveOpenAPIContext(context) {
|
|
8
|
+
const { locale,...rest } = context;
|
|
9
|
+
return {
|
|
10
|
+
...rest,
|
|
11
|
+
translation: translations[locale ?? "en"]
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Get the client context from the OpenAPI context.
|
|
16
|
+
*/
|
|
17
|
+
function getOpenAPIClientContext(context) {
|
|
18
|
+
return {
|
|
19
|
+
translation: context.translation,
|
|
20
|
+
icons: context.icons,
|
|
21
|
+
defaultInteractiveOpened: context.defaultInteractiveOpened,
|
|
22
|
+
blockKey: context.blockKey,
|
|
23
|
+
id: context.id,
|
|
24
|
+
$$isClientContext$$: true
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { getOpenAPIClientContext, resolveOpenAPIContext };
|
package/dist/decycle.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/decycle.ts
|
|
2
|
+
const isObject = (value) => typeof value === "object" && value != null && !(value instanceof Boolean) && !(value instanceof Date) && !(value instanceof Number) && !(value instanceof RegExp) && !(value instanceof String);
|
|
3
|
+
const toPointer = (parts) => `#${parts.map((part) => String(part).replace(/~/g, "~0").replace(/\//g, "~1")).join("/")}`;
|
|
4
|
+
const decycle = () => {
|
|
5
|
+
const paths = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
return function replacer(key, value) {
|
|
7
|
+
if (key !== "$reference" && isObject(value)) {
|
|
8
|
+
if (paths.has(value)) return { $reference: toPointer(paths.get(value)) };
|
|
9
|
+
paths.set(value, [...paths.get(this) ?? [], key]);
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
function retrocycle() {
|
|
15
|
+
const parents = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
const keys = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
const refs = /* @__PURE__ */ new Set();
|
|
18
|
+
function dereference(ref) {
|
|
19
|
+
const parts = ref.$reference.slice(1).split("/");
|
|
20
|
+
let key;
|
|
21
|
+
let value = this;
|
|
22
|
+
for (let i = 0; i < parts.length; i++) {
|
|
23
|
+
key = parts[i]?.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
24
|
+
value = value[key];
|
|
25
|
+
}
|
|
26
|
+
const parent = parents.get(ref);
|
|
27
|
+
parent[keys.get(ref)] = value;
|
|
28
|
+
}
|
|
29
|
+
return function reviver(key, value) {
|
|
30
|
+
if (key === "$reference") refs.add(this);
|
|
31
|
+
else if (isObject(value)) if (key === "" && Object.keys(this).length === 1) refs.forEach(dereference, this);
|
|
32
|
+
else {
|
|
33
|
+
parents.set(value, this);
|
|
34
|
+
keys.set(value, key);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { decycle, retrocycle };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { dereference } from "@gitbook/openapi-parser";
|
|
2
|
+
|
|
3
|
+
//#region src/dereference.ts
|
|
4
|
+
const dereferenceCache = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
/**
|
|
6
|
+
* Memoized version of `dereferenceSchema`.
|
|
7
|
+
*/
|
|
8
|
+
function dereferenceFilesystem(filesystem) {
|
|
9
|
+
if (dereferenceCache.has(filesystem)) return dereferenceCache.get(filesystem);
|
|
10
|
+
const promise = baseDereferenceFilesystem(filesystem);
|
|
11
|
+
dereferenceCache.set(filesystem, promise);
|
|
12
|
+
return promise;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Dereference an OpenAPI schema.
|
|
16
|
+
*/
|
|
17
|
+
async function baseDereferenceFilesystem(filesystem) {
|
|
18
|
+
const result = await dereference(filesystem);
|
|
19
|
+
if (!result.schema) throw new Error("Failed to dereference OpenAPI document");
|
|
20
|
+
return result.schema;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { dereferenceFilesystem };
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { checkIsReference } from "./utils.js";
|
|
2
|
+
|
|
3
|
+
//#region src/generateSchemaExample.ts
|
|
4
|
+
/**
|
|
5
|
+
* Generate a JSON example from a schema
|
|
6
|
+
*/
|
|
7
|
+
function generateSchemaExample(schema, options) {
|
|
8
|
+
return getExampleFromSchema(schema, {
|
|
9
|
+
emptyString: "text",
|
|
10
|
+
...options
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Generate an example for a media type.
|
|
15
|
+
*/
|
|
16
|
+
function generateMediaTypeExamples(mediaType, options) {
|
|
17
|
+
if (mediaType.example) return [{
|
|
18
|
+
summary: "default",
|
|
19
|
+
value: mediaType.example
|
|
20
|
+
}];
|
|
21
|
+
if (mediaType.examples) {
|
|
22
|
+
const { examples } = mediaType;
|
|
23
|
+
const keys = Object.keys(examples);
|
|
24
|
+
if (keys.length > 0) return keys.reduce((result, key) => {
|
|
25
|
+
const example = examples[key];
|
|
26
|
+
if (!example || checkIsReference(example)) return result;
|
|
27
|
+
result.push({
|
|
28
|
+
summary: example.summary || key,
|
|
29
|
+
value: example.value,
|
|
30
|
+
description: example.description,
|
|
31
|
+
externalValue: example.externalValue
|
|
32
|
+
});
|
|
33
|
+
return result;
|
|
34
|
+
}, []);
|
|
35
|
+
}
|
|
36
|
+
if (mediaType.schema) return [{
|
|
37
|
+
summary: "default",
|
|
38
|
+
value: generateSchemaExample(mediaType.schema, options)
|
|
39
|
+
}];
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
/** Hard limit for rendering circular references */
|
|
43
|
+
const MAX_LEVELS_DEEP = 5;
|
|
44
|
+
const genericExampleValues = {
|
|
45
|
+
"date-time": (/* @__PURE__ */ new Date()).toISOString(),
|
|
46
|
+
date: (/* @__PURE__ */ new Date()).toISOString().split("T")[0] ?? "1970-01-01",
|
|
47
|
+
email: "name@gmail.com",
|
|
48
|
+
hostname: "example.com",
|
|
49
|
+
ipv4: "0.0.0.0",
|
|
50
|
+
ipv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
|
|
51
|
+
uri: "https://example.com",
|
|
52
|
+
uuid: "123e4567-e89b-12d3-a456-426614174000",
|
|
53
|
+
binary: "binary",
|
|
54
|
+
byte: "Ynl0ZXM=",
|
|
55
|
+
password: "password",
|
|
56
|
+
"idn-email": "jane.doe@example.com",
|
|
57
|
+
"idn-hostname": "example.com",
|
|
58
|
+
"iri-reference": "/entitiy/1",
|
|
59
|
+
iri: "https://example.com/entity/123",
|
|
60
|
+
"json-pointer": "/nested/objects",
|
|
61
|
+
regex: "/[a-z]/",
|
|
62
|
+
"relative-json-pointer": "1/nested/objects",
|
|
63
|
+
time: (/* @__PURE__ */ new Date()).toISOString().split("T")[1]?.split(".")[0] ?? "00:00:00Z",
|
|
64
|
+
"uri-reference": "../folder",
|
|
65
|
+
"uri-template": "https://example.com/{id}",
|
|
66
|
+
"object-id": "6592008029c8c3e4dc76256c"
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* We can use the `format` to generate some random values.
|
|
70
|
+
*/
|
|
71
|
+
function guessFromFormat(schema, fallback = "") {
|
|
72
|
+
return genericExampleValues[schema.format] ?? fallback;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* This function takes an OpenAPI schema and generates an example from it
|
|
76
|
+
* Forked from : https://github.com/scalar/scalar/blob/main/packages/oas-utils/src/spec-getters/getExampleFromSchema.ts
|
|
77
|
+
*/
|
|
78
|
+
const getExampleFromSchema = (schema, options, level = 0, parentSchema, name, resultCache = /* @__PURE__ */ new WeakMap()) => {
|
|
79
|
+
function cache(schema$1, result) {
|
|
80
|
+
if (typeof result !== "object" || result === null) return result;
|
|
81
|
+
resultCache.set(schema$1, result);
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
if (resultCache.has(schema)) return resultCache.get(schema);
|
|
85
|
+
if (level === MAX_LEVELS_DEEP + 1) try {
|
|
86
|
+
JSON.stringify(schema);
|
|
87
|
+
} catch {
|
|
88
|
+
return "[Circular Reference]";
|
|
89
|
+
}
|
|
90
|
+
const makeUpRandomData = !!options?.emptyString;
|
|
91
|
+
if (schema.deprecated || schema.type === "array" && schema.items?.deprecated) return;
|
|
92
|
+
if (options?.mode === "write" && schema.readOnly || options?.mode === "read" && schema.writeOnly) return;
|
|
93
|
+
if (schema["x-variable"]) {
|
|
94
|
+
const value = options?.variables?.[schema["x-variable"]];
|
|
95
|
+
if (value !== void 0) {
|
|
96
|
+
if (schema.type === "number" || schema.type === "integer") return Number.parseInt(value, 10);
|
|
97
|
+
return cache(schema, value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (Array.isArray(schema.examples) && schema.examples.length > 0) return cache(schema, schema.examples[0]);
|
|
101
|
+
if (schema.example !== void 0) return cache(schema, schema.example);
|
|
102
|
+
if (schema.default !== void 0 && [
|
|
103
|
+
"string",
|
|
104
|
+
"number",
|
|
105
|
+
"boolean"
|
|
106
|
+
].includes(typeof schema.default)) return cache(schema, schema.default);
|
|
107
|
+
if (Array.isArray(schema.enum) && schema.enum.length > 0) return cache(schema, schema.enum[0]);
|
|
108
|
+
if (!(schema.type === "object" || schema.type === "array" || !!schema.allOf?.at?.(0) || !!schema.anyOf?.at?.(0) || !!schema.oneOf?.at?.(0)) && options?.omitEmptyAndOptionalProperties === true) {
|
|
109
|
+
if (!(schema.required === true || parentSchema?.required === true || parentSchema?.required?.includes(name ?? schema.name))) return;
|
|
110
|
+
}
|
|
111
|
+
if (schema.type === "object" || schema.properties !== void 0) {
|
|
112
|
+
const response = {};
|
|
113
|
+
if (schema.properties !== void 0) {
|
|
114
|
+
for (const propertyName in schema.properties) if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {
|
|
115
|
+
const property = schema.properties[propertyName];
|
|
116
|
+
const propertyXmlTagName = options?.xml ? property.xml?.name : void 0;
|
|
117
|
+
response[propertyXmlTagName ?? propertyName] = getExampleFromSchema(property, options, level + 1, schema, propertyName, resultCache);
|
|
118
|
+
if (typeof response[propertyXmlTagName ?? propertyName] === "undefined") delete response[propertyXmlTagName ?? propertyName];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (schema.patternProperties !== void 0) {
|
|
122
|
+
for (const pattern in schema.patternProperties) if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {
|
|
123
|
+
const property = schema.patternProperties[pattern];
|
|
124
|
+
const exampleKey = pattern;
|
|
125
|
+
response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey, resultCache);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (schema.additionalProperties !== void 0) {
|
|
129
|
+
if (schema.additionalProperties === true || typeof schema.additionalProperties === "object" && !Object.keys(schema.additionalProperties).length) response.ANY_ADDITIONAL_PROPERTY = "anything";
|
|
130
|
+
else if (schema.additionalProperties !== false) response.ANY_ADDITIONAL_PROPERTY = getExampleFromSchema(schema.additionalProperties, options, level + 1, void 0, void 0, resultCache);
|
|
131
|
+
}
|
|
132
|
+
if (schema.anyOf !== void 0) Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1, void 0, void 0, resultCache));
|
|
133
|
+
else if (schema.oneOf !== void 0) Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1, void 0, void 0, resultCache));
|
|
134
|
+
else if (schema.allOf !== void 0) Object.assign(response, ...schema.allOf.map((item) => getExampleFromSchema(item, options, level + 1, schema, void 0, resultCache)).filter((item) => item !== void 0));
|
|
135
|
+
return cache(schema, response);
|
|
136
|
+
}
|
|
137
|
+
if (schema.type === "array" || schema.items !== void 0) {
|
|
138
|
+
const itemsXmlTagName = schema?.items?.xml?.name;
|
|
139
|
+
const wrapItems = !!(options?.xml && schema.xml?.wrapped && itemsXmlTagName);
|
|
140
|
+
if (schema.example !== void 0) return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example);
|
|
141
|
+
if (schema.items) {
|
|
142
|
+
if (schema.items.allOf) {
|
|
143
|
+
if (schema.items.allOf[0].type === "object") {
|
|
144
|
+
const mergedExample = getExampleFromSchema({
|
|
145
|
+
type: "object",
|
|
146
|
+
allOf: schema.items.allOf
|
|
147
|
+
}, options, level + 1, schema, void 0, resultCache);
|
|
148
|
+
return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample]);
|
|
149
|
+
}
|
|
150
|
+
const examples = schema.items.allOf.map((item) => getExampleFromSchema(item, options, level + 1, schema, void 0, resultCache)).filter((item) => item !== void 0);
|
|
151
|
+
return cache(schema, wrapItems ? examples.map((example) => ({ [itemsXmlTagName]: example })) : examples);
|
|
152
|
+
}
|
|
153
|
+
for (const rule of ["anyOf", "oneOf"]) {
|
|
154
|
+
if (!schema.items[rule]) continue;
|
|
155
|
+
const exampleFromRule = schema.items[rule].slice(0, 1).map((item) => getExampleFromSchema(item, options, level + 1, schema, void 0, resultCache)).filter((item) => item !== void 0);
|
|
156
|
+
return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (schema.items?.type) {
|
|
160
|
+
const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1, void 0, void 0, resultCache);
|
|
161
|
+
return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema];
|
|
162
|
+
}
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
const exampleValues = {
|
|
166
|
+
string: makeUpRandomData ? guessFromFormat(schema, options?.emptyString) : "",
|
|
167
|
+
boolean: true,
|
|
168
|
+
integer: schema.min ?? 1,
|
|
169
|
+
number: schema.min ?? 1,
|
|
170
|
+
array: []
|
|
171
|
+
};
|
|
172
|
+
if (schema.type !== void 0 && exampleValues[schema.type] !== void 0) return cache(schema, exampleValues[schema.type]);
|
|
173
|
+
const discriminateSchema = schema.oneOf || schema.anyOf;
|
|
174
|
+
if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {
|
|
175
|
+
const firstOneOfItem = discriminateSchema[0];
|
|
176
|
+
return getExampleFromSchema(firstOneOfItem, options, level + 1, void 0, void 0, resultCache);
|
|
177
|
+
}
|
|
178
|
+
if (Array.isArray(schema.allOf)) {
|
|
179
|
+
let example = null;
|
|
180
|
+
schema.allOf.forEach((allOfItem) => {
|
|
181
|
+
const newExample = getExampleFromSchema(allOfItem, options, level + 1, void 0, void 0, resultCache);
|
|
182
|
+
example = typeof newExample === "object" && typeof example === "object" ? {
|
|
183
|
+
...example ?? {},
|
|
184
|
+
...newExample
|
|
185
|
+
} : Array.isArray(newExample) && Array.isArray(example) ? [...example ?? {}, ...newExample] : newExample;
|
|
186
|
+
});
|
|
187
|
+
return cache(schema, example);
|
|
188
|
+
}
|
|
189
|
+
if (Array.isArray(schema.type)) {
|
|
190
|
+
if (schema.type.includes("null")) return null;
|
|
191
|
+
const exampleValue = exampleValues[schema.type[0]];
|
|
192
|
+
if (exampleValue !== void 0) return cache(schema, exampleValue);
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
//#endregion
|
|
198
|
+
export { generateMediaTypeExamples, generateSchemaExample };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { tString } from "./translate.js";
|
|
5
|
+
|
|
6
|
+
//#region src/getDisclosureLabel.ts
|
|
7
|
+
function getDisclosureLabel(props) {
|
|
8
|
+
const { schema, isExpanded, context } = props;
|
|
9
|
+
let label;
|
|
10
|
+
if (schema.type === "array" && !!schema.items) if (schema.items.oneOf) label = tString(context.translation, "available_items").toLowerCase();
|
|
11
|
+
else label = tString(context.translation, "properties").toLowerCase();
|
|
12
|
+
else label = tString(context.translation, "properties").toLowerCase();
|
|
13
|
+
return tString(context.translation, isExpanded ? "hide" : "show", label);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { getDisclosureLabel };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createStore } from "zustand";
|
|
2
|
+
|
|
3
|
+
//#region src/getOrCreateStoreByKey.ts
|
|
4
|
+
const createStateStore = (initial) => {
|
|
5
|
+
return createStore()((set) => ({
|
|
6
|
+
key: initial ?? null,
|
|
7
|
+
setKey: (key) => {
|
|
8
|
+
set(() => ({ key }));
|
|
9
|
+
}
|
|
10
|
+
}));
|
|
11
|
+
};
|
|
12
|
+
const defaultStores = /* @__PURE__ */ new Map();
|
|
13
|
+
const createStateStoreFactory = (stores) => {
|
|
14
|
+
return (storeKey, initialKey) => {
|
|
15
|
+
if (!stores.has(storeKey)) stores.set(storeKey, createStateStore(initialKey));
|
|
16
|
+
return stores.get(storeKey);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
const getOrCreateStoreByKey = createStateStoreFactory(defaultStores);
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { getOrCreateStoreByKey };
|