@satoshibits/react-json-schema-builder 1.1.2 → 1.1.4
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/index.cjs2.js +1 -1
- package/dist/index.cjs2.js.map +1 -1
- package/dist/index.cjs21.js +1 -1
- package/dist/index.cjs21.js.map +1 -1
- package/dist/index.cjs31.js +1 -1
- package/dist/index.cjs34.js +1 -1
- package/dist/index.cjs36.js +1 -1
- package/dist/index.cjs37.js +1 -1
- package/dist/index.cjs41.js +1 -1
- package/dist/index.cjs43.js +1 -1
- package/dist/index.cjs47.js +1 -1
- package/dist/index.cjs55.js +5 -1
- package/dist/index.cjs55.js.map +1 -1
- package/dist/index.cjs56.js +1 -1
- package/dist/index.cjs56.js.map +1 -1
- package/dist/index.cjs57.js +1 -1
- package/dist/index.cjs57.js.map +1 -1
- package/dist/index.cjs58.js +1 -1
- package/dist/index.cjs58.js.map +1 -1
- package/dist/index.cjs59.js +1 -1
- package/dist/index.cjs59.js.map +1 -1
- package/dist/index.cjs60.js +1 -1
- package/dist/index.cjs60.js.map +1 -1
- package/dist/index.cjs61.js +1 -1
- package/dist/index.cjs61.js.map +1 -1
- package/dist/index.cjs62.js +1 -1
- package/dist/index.cjs62.js.map +1 -1
- package/dist/index.cjs63.js +1 -1
- package/dist/index.cjs63.js.map +1 -1
- package/dist/index.cjs64.js +1 -1
- package/dist/index.cjs64.js.map +1 -1
- package/dist/index.cjs65.js +1 -1
- package/dist/index.cjs65.js.map +1 -1
- package/dist/index.cjs66.js +1 -1
- package/dist/index.cjs66.js.map +1 -1
- package/dist/index.cjs67.js +1 -1
- package/dist/index.cjs67.js.map +1 -1
- package/dist/index.cjs68.js +1 -1
- package/dist/index.cjs68.js.map +1 -1
- package/dist/index.cjs69.js +1 -1
- package/dist/index.cjs69.js.map +1 -1
- package/dist/index.cjs70.js +1 -1
- package/dist/index.cjs70.js.map +1 -1
- package/dist/index.cjs71.js +1 -1
- package/dist/index.cjs71.js.map +1 -1
- package/dist/index.cjs72.js +1 -1
- package/dist/index.cjs72.js.map +1 -1
- package/dist/index.cjs73.js +1 -1
- package/dist/index.cjs73.js.map +1 -1
- package/dist/index.cjs74.js +1 -1
- package/dist/index.cjs74.js.map +1 -1
- package/dist/index.cjs75.js +1 -1
- package/dist/index.cjs75.js.map +1 -1
- package/dist/index.cjs76.js +1 -5
- package/dist/index.cjs76.js.map +1 -1
- package/dist/index.cjs77.js +1 -1
- package/dist/index.cjs77.js.map +1 -1
- package/dist/index.cjs78.js +1 -1
- package/dist/index.cjs80.js +1 -1
- package/dist/index.cjs82.js +1 -1
- package/dist/index.cjs87.js +1 -1
- package/dist/index.cjs89.js +1 -1
- package/dist/index.cjs94.js +1 -38
- package/dist/index.cjs94.js.map +1 -1
- package/dist/index.cjs95.js +38 -1
- package/dist/index.cjs95.js.map +1 -1
- package/dist/index.cjs96.js +1 -1
- package/dist/index.cjs96.js.map +1 -1
- package/dist/index.cjs97.js +1 -1
- package/dist/index.cjs97.js.map +1 -1
- package/dist/index.cjs98.js +1 -1
- package/dist/index.cjs98.js.map +1 -1
- package/dist/index.es2.js +23 -21
- package/dist/index.es2.js.map +1 -1
- package/dist/index.es21.js +48 -45
- package/dist/index.es21.js.map +1 -1
- package/dist/index.es31.js +1 -1
- package/dist/index.es34.js +1 -1
- package/dist/index.es36.js +7 -7
- package/dist/index.es37.js +20 -20
- package/dist/index.es41.js +1 -1
- package/dist/index.es43.js +1 -1
- package/dist/index.es47.js +4 -4
- package/dist/index.es55.js +252 -30
- package/dist/index.es55.js.map +1 -1
- package/dist/index.es56.js +21 -6
- package/dist/index.es56.js.map +1 -1
- package/dist/index.es57.js +5 -25
- package/dist/index.es57.js.map +1 -1
- package/dist/index.es58.js +23 -62
- package/dist/index.es58.js.map +1 -1
- package/dist/index.es59.js +63 -27
- package/dist/index.es59.js.map +1 -1
- package/dist/index.es60.js +29 -5
- package/dist/index.es60.js.map +1 -1
- package/dist/index.es61.js +5 -24
- package/dist/index.es61.js.map +1 -1
- package/dist/index.es62.js +24 -3
- package/dist/index.es62.js.map +1 -1
- package/dist/index.es63.js +32 -45
- package/dist/index.es63.js.map +1 -1
- package/dist/index.es64.js +3 -7
- package/dist/index.es64.js.map +1 -1
- package/dist/index.es65.js +44 -123
- package/dist/index.es65.js.map +1 -1
- package/dist/index.es66.js +7 -14
- package/dist/index.es66.js.map +1 -1
- package/dist/index.es67.js +116 -125
- package/dist/index.es67.js.map +1 -1
- package/dist/index.es68.js +14 -10
- package/dist/index.es68.js.map +1 -1
- package/dist/index.es69.js +127 -209
- package/dist/index.es69.js.map +1 -1
- package/dist/index.es70.js +10 -12
- package/dist/index.es70.js.map +1 -1
- package/dist/index.es71.js +215 -7
- package/dist/index.es71.js.map +1 -1
- package/dist/index.es72.js +13 -4
- package/dist/index.es72.js.map +1 -1
- package/dist/index.es73.js +7 -27
- package/dist/index.es73.js.map +1 -1
- package/dist/index.es74.js +3 -49
- package/dist/index.es74.js.map +1 -1
- package/dist/index.es75.js +28 -9
- package/dist/index.es75.js.map +1 -1
- package/dist/index.es76.js +48 -253
- package/dist/index.es76.js.map +1 -1
- package/dist/index.es77.js +8 -21
- package/dist/index.es77.js.map +1 -1
- package/dist/index.es78.js +1 -1
- package/dist/index.es80.js +1 -1
- package/dist/index.es82.js +2 -2
- package/dist/index.es87.js +1 -1
- package/dist/index.es89.js +4 -4
- package/dist/index.es94.js +65 -69
- package/dist/index.es94.js.map +1 -1
- package/dist/index.es95.js +68 -8
- package/dist/index.es95.js.map +1 -1
- package/dist/index.es96.js +9 -14
- package/dist/index.es96.js.map +1 -1
- package/dist/index.es97.js +14 -62
- package/dist/index.es97.js.map +1 -1
- package/dist/index.es98.js +61 -64
- package/dist/index.es98.js.map +1 -1
- package/dist/packages/builder/add-dialog.d.ts.map +1 -1
- package/dist/packages/builder/context.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs2.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("react/jsx-runtime"),d=require("react"),x=require("./index.cjs9.js"),m=require("./index.cjs10.js"),h=d.createContext(void 0),C={$schema:"http://json-schema.org/draft-07/schema#",type:"object",title:"title",description:"",properties:{},required:[]};function O({children:c,initialSchema:f}){const[p,n]=d.useState(f??C),[u,a]=d.useState([]);return w.jsx(h.Provider,{value:{schema:p,setSchema:n,path:u,setPath:a},children:c})}function R({onSchemaChange:c}={}){const f=d.useContext(h);if(f===void 0)throw new Error("useSchema must be used within a SchemaProvider");const{path:p,schema:n,setSchema:u}=f,a=(r,e)=>{let t=r,i=null,o=null;for(const s of e)t.type==="array"&&t.items&&!Array.isArray(t.items)&&typeof t.items=="object"&&t.items.type==="object"&&typeof t.items.properties?.[s]=="object"?(o=t.items,i=t.items.properties[s],t=t.items):t.type==="object"&&t.properties&&!Array.isArray(t.properties)&&typeof t.properties[s]=="object"&&(o=t,i=t.properties[s],t=t.properties[s]);return{propertySchema:i,parentSchema:o}},l=r=>{const{propertySchema:e}=a(r??n,p);return e?e.type==="array"?e.items:e:r??n},b=()=>{const{propertySchema:r}=a(n,p);return r},j=(r,e)=>{const t=m.a(n),i=l(t);if(i.properties?.[r]){const o=Object.entries(i.properties).map(([s,v])=>[s===r?e:s,v]);i.properties=Object.fromEntries(o)}i.required?.includes(r)&&(i.required=i.required.map(o=>o===r?e:o)),u(t),c?.(t)},S=(r,e)=>{const t=m.a(n),i=l(t);typeof e=="object"&&"isRequired"in e&&(i.type==="object"&&(i.required||(i.required=[]),e.isRequired?i.required.includes(r)||i.required.push(r):i.required=i.required.filter(s=>s!==r)),delete e.isRequired);let o=!1;if(i.type==="object"&&i.properties){const s=i.properties[r];typeof s!="boolean"&&s&&typeof e!="boolean"&&(e.type&&e.type!==s.type?e={title:s.title,description:s.description,default:s.default,...e}:e.enum?(delete e.type,delete e.items,delete e.properties,e={title:s.title,description:s.description,...e}):e={...s,...e},i.properties[r]=e),o=!0}if(u(t),c?.(t),o)return{status:"success",property:i.properties[r]}},y=(r,e,t)=>{const i=m.a(n),o=l(i);return o.type!=="object"&&(o.type="object"),o.properties||(o.properties={}),o.properties[r]?{status:"error",code:"key-exists",message:`Property with key ${r} already exists`}:(e.enum&&(delete e.type,delete e.items,delete e.properties),e=Object.fromEntries(Object.entries(e).filter(([,s])=>s!==void 0)),o.properties[r]=e,t&&(o.required||(o.required=[]),o.required.includes(r)||o.required.push(r)),u(i),c?.(i),{status:"success",property:o.properties[r]})},P=r=>{const e=m.a(n),t=l(e);t.type==="object"&&t.required&&(t.required=t.required.filter(i=>i!==r)),t.type==="object"&&t.properties&&delete t.properties[r],u(e),c?.(e)},g=r=>{const e=l().properties;if(!e||x.a(e)||typeof e[r]=="boolean")return;const t=e[r],i=`${r}_copy`,o=m.a(t);return y(i,o,q(r))},q=r=>{if(p.length){const{propertySchema:e}=a(n,p);return e?.type==="array"&&e.items&&typeof e.items!="boolean"&&!Array.isArray(e.items)&&e.items?.type==="object"?!!e.items?.required?.includes(r):!!e?.required?.includes(r)}return!!n?.required?.includes(r)};return{...f,getCurrentSchema:l,getCurrentProperty:b,handlePropertyChange:S,handleAddProperty:y,handleKeyChange:j,navigateToCorrectNesting:a,handleDeleteProperty:P,isPropertyRequired:q,getValue:()=>n,handleDuplicateProperty:g}}exports.SchemaContext=h;exports.SchemaProvider=O;exports.useSchema=R;
|
|
2
2
|
//# sourceMappingURL=index.cjs2.js.map
|
package/dist/index.cjs2.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs2.js","sources":["../src/packages/builder/context.tsx"],"sourcesContent":["import { createContext, useContext, useState } from \"react\";\n\nimport type { PropsWithChildren, SetStateAction } from \"react\";\nimport type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\nimport { clone, isEmpty } from \"remeda\";\nimport type { OperationError } from \"./shared-types\";\n\ninterface ContextState<T extends JSONSchema7> {\n schema: T;\n setSchema: React.Dispatch<T>;\n path: string[];\n setPath: React.Dispatch<SetStateAction<string[]>>;\n}\n\nexport const SchemaContext = createContext<\n ContextState<JSONSchema7> | undefined\n>(undefined);\n\nconst defaultSchema: JSONSchema7 = {\n $schema: \"http://json-schema.org/draft-07/schema#\",\n type: \"object\",\n title: \"title\",\n description: \"\",\n properties: {},\n required: [],\n};\n\nfunction SchemaProvider({\n children,\n initialSchema,\n}: PropsWithChildren<{ initialSchema?: JSONSchema7 }>) {\n const [schema, setSchema] = useState<JSONSchema7>(\n initialSchema ?? defaultSchema,\n );\n\n /**\n * Path represents the path to a nested property in the schema.\n * It should only contain property keys.\n * An empty path means the current schema is the root schema since\n * the path only represents nested properties.\n */\n const [path, setPath] = useState<string[]>([]);\n\n // NOTE: you *might* need to memoize your values\n // Learn more in http://kcd.im/optimize-context\n\n return (\n <SchemaContext.Provider value={{ schema, setSchema, path, setPath }}>\n {children}\n </SchemaContext.Provider>\n );\n}\n\nexport type PropertyAddError = OperationError & {\n status: \"error\";\n};\n\nexport interface PropertyAddSuccess {\n status: \"success\";\n property: JSONSchema7;\n}\n\nexport interface PropertyChangeSuccess {\n status: \"success\";\n property: JSONSchema7Definition;\n}\n\nfunction useSchema({\n onSchemaChange,\n}: {\n onSchemaChange?: (schema: JSONSchema7) => void;\n} = {}) {\n const context = useContext(SchemaContext);\n\n if (context === undefined) {\n throw new Error(\"useSchema must be used within a SchemaProvider\");\n }\n\n const { path, schema, setSchema } = context;\n\n /**\n * Navigates to the correct property schema of the latest key in the provided path.\n *\n * It will traverse both \"properties\" and \"items\" to find the correct property schema.\n *\n * It will only return a property schema if the provided path is valid i.e. it\n * correctly follows the schema's nesting structure.\n *\n * It will only return a parent schema if the provided path is valid i.e. it\n * correctly follows the schema's nesting structure.\n */\n const navigateToCorrectNesting = (\n providedSchema: JSONSchema7,\n providedPath: string[],\n ) => {\n let current = providedSchema;\n let propertySchema: JSONSchema7 | null = null;\n // Should be the schema of type \"object\" containing the property in its properties key\n let parentSchema: JSONSchema7 | null = null;\n\n for (const p of providedPath) {\n if (\n current.type === \"array\" &&\n current.items &&\n !Array.isArray(current.items) &&\n typeof current.items === \"object\" &&\n current.items.type === \"object\" &&\n typeof current.items.properties?.[p] === \"object\"\n ) {\n parentSchema = current.items;\n propertySchema = current.items.properties[p];\n current = current.items;\n } else if (\n current.type === \"object\" &&\n current.properties &&\n !Array.isArray(current.properties) &&\n typeof current.properties[p] === \"object\"\n ) {\n parentSchema = current;\n propertySchema = current.properties[p];\n current = current.properties[p];\n }\n }\n\n return { propertySchema, parentSchema };\n };\n\n /**\n * Gets the current schema of the latest key in the path.\n * If path is empty, it will return the root schema.\n *\n * It should always return the \"object\" schema of the current path.\n */\n const getCurrentSchema = (initialSchema?: JSONSchema7) => {\n // Gets the correct object schema if under nesting\n // Otherwise, return the root schema\n const { propertySchema } = navigateToCorrectNesting(\n initialSchema ?? schema,\n path,\n );\n\n if (propertySchema) {\n if (propertySchema.type === \"array\") {\n return propertySchema.items as JSONSchema7;\n }\n\n return propertySchema;\n }\n\n return initialSchema ?? schema;\n };\n\n /**\n * Gets the correct property schema of the latest key in the path.\n * If no path is provided, it will return null.\n */\n const getCurrentProperty = () => {\n const { propertySchema } = navigateToCorrectNesting(schema, path);\n\n return propertySchema;\n };\n\n /**\n * Change the key of a property in the schema. It expects\n * the find the key at the current path.\n */\n const handleKeyChange = (key: string, newKey: string) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to change\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n if (current.properties?.[key]) {\n //Important: maintain order as to not confuse users\n const newProperties = Object.entries(current.properties).map(\n ([k, val]) => {\n return [k === key ? newKey : k, val];\n },\n );\n\n current.properties = Object.fromEntries(\n newProperties,\n ) as JSONSchema7[\"properties\"];\n }\n\n if (current.required?.includes(key)) {\n current.required = current.required.map((item) =>\n item === key ? newKey : item,\n );\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n };\n\n const handlePropertyChange = (\n key: string,\n updates: Partial<JSONSchema7Definition> & { isRequired?: boolean },\n ): PropertyChangeSuccess | undefined => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to change\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Handle required field updates\n if (typeof updates === \"object\" && \"isRequired\" in updates) {\n if (current.type === \"object\") {\n if (!current.required) {\n current.required = [];\n }\n if (updates.isRequired) {\n if (!current.required.includes(key)) {\n current.required.push(key);\n }\n } else {\n current.required = current.required.filter((item) => item !== key);\n }\n }\n delete updates.isRequired;\n }\n\n let isUpdated = false;\n\n // Update the property\n if (current.type === \"object\" && current.properties) {\n const originalProperty = current.properties[key];\n // Ensure the property exists and is not a boolean\n if (typeof originalProperty !== \"boolean\" && originalProperty) {\n if (typeof updates !== \"boolean\") {\n //if updates changes the type of the property,\n //only the title, description, and default properties should remain\n //from the original property\n if (updates.type && updates.type !== originalProperty.type) {\n updates = {\n title: originalProperty.title,\n description: originalProperty.description,\n default: originalProperty.default,\n ...updates,\n };\n } else if (updates.enum) {\n //if the property is an enum, only the title and description should remain\n //from the original property\n delete updates.type;\n delete updates.items;\n delete updates.properties;\n updates = {\n title: originalProperty.title,\n description: originalProperty.description,\n ...updates,\n };\n } else {\n updates = { ...originalProperty, ...updates };\n }\n\n current.properties[key] = updates;\n }\n }\n isUpdated = true;\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n\n if (isUpdated) {\n return { status: \"success\", property: current.properties![key]! };\n }\n };\n\n /**\n * Adds a sibling property to the current schema.\n */\n const handleAddProperty = (\n key: string,\n propertyToAdd: JSONSchema7,\n isRequired: boolean,\n ) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to add\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Ensure the current schema has a properties object\n if (current.type !== \"object\") {\n current.type = \"object\";\n }\n if (!current.properties) {\n current.properties = {};\n }\n\n //Ensure there's no existing property with the same key\n if (current.properties[key]) {\n return {\n status: \"error\",\n code: \"key-exists\" as const,\n message: `Property with key ${key} already exists`,\n } satisfies PropertyAddError;\n }\n\n if (propertyToAdd.enum) {\n //ensure that only the enum property is present\n delete propertyToAdd.type;\n delete propertyToAdd.items;\n delete propertyToAdd.properties;\n }\n\n // Add the new property\n current.properties[key] = propertyToAdd;\n\n // Handle required field\n if (isRequired) {\n if (!current.required) {\n current.required = [];\n }\n if (!current.required.includes(key)) {\n current.required.push(key);\n }\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n\n return {\n status: \"success\" as const,\n property: current.properties[key],\n } satisfies PropertyAddSuccess;\n };\n\n const handleDeleteProperty = (key: string) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to delete\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Handle required field updates\n if (current.type === \"object\") {\n if (current.required) {\n current.required = current.required.filter((item) => item !== key);\n }\n }\n\n // Delete the property\n if (current.type === \"object\" && current.properties) {\n delete current.properties[key];\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n };\n\n const handleDuplicateProperty = (key: string) => {\n const currentProperties = getCurrentSchema().properties;\n if (\n !currentProperties ||\n isEmpty(currentProperties) ||\n typeof currentProperties[key] === \"boolean\"\n ) {\n return;\n }\n\n const propertyToDuplicate = currentProperties[key]!;\n const newKey = `${key}_copy`;\n const newProperty = clone(propertyToDuplicate);\n\n // Add the duplicated property\n return handleAddProperty(newKey, newProperty, isPropertyRequired(key));\n };\n\n const isPropertyRequired = (key: string) => {\n if (path.length) {\n const { propertySchema } = navigateToCorrectNesting(schema, path);\n\n if (\n propertySchema?.type === \"array\" &&\n propertySchema.items &&\n typeof propertySchema.items !== \"boolean\" &&\n !Array.isArray(propertySchema.items) &&\n propertySchema.items?.type === \"object\"\n ) {\n return Boolean(propertySchema.items?.required?.includes(key));\n } else {\n return Boolean(propertySchema?.required?.includes(key));\n }\n }\n\n return Boolean(schema?.required?.includes(key));\n };\n\n /**\n * Programatically get the current schema value\n */\n const getValue = () => {\n return schema;\n };\n\n return {\n ...context,\n getCurrentSchema,\n getCurrentProperty,\n handlePropertyChange,\n handleAddProperty,\n handleKeyChange,\n navigateToCorrectNesting,\n handleDeleteProperty,\n isPropertyRequired,\n getValue,\n handleDuplicateProperty,\n };\n}\n\nexport { SchemaProvider, useSchema };\n"],"names":["SchemaContext","createContext","defaultSchema","SchemaProvider","children","initialSchema","schema","setSchema","useState","path","setPath","jsx","useSchema","onSchemaChange","context","useContext","navigateToCorrectNesting","providedSchema","providedPath","current","propertySchema","parentSchema","p","getCurrentSchema","getCurrentProperty","handleKeyChange","key","newKey","newSchema","clone","newProperties","k","val","item","handlePropertyChange","updates","isUpdated","originalProperty","handleAddProperty","propertyToAdd","isRequired","handleDeleteProperty","handleDuplicateProperty","currentProperties","isEmpty","propertyToDuplicate","newProperty","isPropertyRequired"],"mappings":"mMAcaA,EAAgBC,gBAE3B,MAAS,EAELC,EAA6B,CACjC,QAAS,0CACT,KAAM,SACN,MAAO,QACP,YAAa,GACb,WAAY,CAAC,EACb,SAAU,CAAA,CACZ,EAEA,SAASC,EAAe,CACtB,SAAAC,EACA,cAAAC,CACF,EAAuD,CAC/C,KAAA,CAACC,EAAQC,CAAS,EAAIC,EAAA,SAC1BH,GAAiBH,CACnB,EAQM,CAACO,EAAMC,CAAO,EAAIF,EAAAA,SAAmB,CAAA,CAAE,EAM3C,OAAAG,MAACX,EAAc,SAAd,CAAuB,MAAO,CAAE,OAAAM,EAAQ,UAAAC,EAAW,KAAAE,EAAM,QAAAC,CAAQ,EAC/D,SAAAN,CACH,CAAA,CAEJ,CAgBA,SAASQ,EAAU,CACjB,eAAAC,CACF,EAEI,GAAI,CACA,MAAAC,EAAUC,aAAWf,CAAa,EAExC,GAAIc,IAAY,OACR,MAAA,IAAI,MAAM,gDAAgD,EAGlE,KAAM,CAAE,KAAAL,EAAM,OAAAH,EAAQ,UAAAC,CAAc,EAAAO,EAa9BE,EAA2B,CAC/BC,EACAC,IACG,CACH,IA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G,CAAI,EAEhE,OACEW,GAAgB,OAAS,SACzBA,EAAe,OACf,OAAOA,EAAe,OAAU,WAChC,CAAC,MAAM,QAAQA,EAAe,KAAK,GACnCA,EAAe,OAAO,OAAS,SAExB,EAAQA,EAAe,OAAO,UAAU,SAASM,CAAG,EAEpD,EAAQN,GAAgB,UAAU,SAASM,CAAG,CACvD,CAGF,MAAO,EAAQpB,GAAQ,UAAU,SAASoB,CAAG,CAC/C,EASO,MAAA,CACL,GAAGZ,EACH,iBAAAS,EACA,mBAAAC,EACA,qBAAAU,EACA,kBAAAI,EACA,gBAAAb,EACA,yBAAAT,EACA,qBAAAyB,EACA,mBAAAM,EACA,SAde,IACRzC,EAcP,wBAAAoC,CACF,CACF"}
|
|
1
|
+
{"version":3,"file":"index.cjs2.js","sources":["../src/packages/builder/context.tsx"],"sourcesContent":["import { createContext, useContext, useState } from \"react\";\n\nimport type { PropsWithChildren, SetStateAction } from \"react\";\nimport type { JSONSchema7, JSONSchema7Definition } from \"json-schema\";\nimport { clone, isEmpty } from \"remeda\";\nimport type { OperationError } from \"./shared-types\";\n\ninterface ContextState<T extends JSONSchema7> {\n schema: T;\n setSchema: React.Dispatch<T>;\n path: string[];\n setPath: React.Dispatch<SetStateAction<string[]>>;\n}\n\nexport const SchemaContext = createContext<\n ContextState<JSONSchema7> | undefined\n>(undefined);\n\nconst defaultSchema: JSONSchema7 = {\n $schema: \"http://json-schema.org/draft-07/schema#\",\n type: \"object\",\n title: \"title\",\n description: \"\",\n properties: {},\n required: [],\n};\n\nfunction SchemaProvider({\n children,\n initialSchema,\n}: PropsWithChildren<{ initialSchema?: JSONSchema7 }>) {\n const [schema, setSchema] = useState<JSONSchema7>(\n initialSchema ?? defaultSchema,\n );\n\n /**\n * Path represents the path to a nested property in the schema.\n * It should only contain property keys.\n * An empty path means the current schema is the root schema since\n * the path only represents nested properties.\n */\n const [path, setPath] = useState<string[]>([]);\n\n // NOTE: you *might* need to memoize your values\n // Learn more in http://kcd.im/optimize-context\n\n return (\n <SchemaContext.Provider value={{ schema, setSchema, path, setPath }}>\n {children}\n </SchemaContext.Provider>\n );\n}\n\nexport type PropertyAddError = OperationError & {\n status: \"error\";\n};\n\nexport interface PropertyAddSuccess {\n status: \"success\";\n property: JSONSchema7;\n}\n\nexport interface PropertyChangeSuccess {\n status: \"success\";\n property: JSONSchema7Definition;\n}\n\nfunction useSchema({\n onSchemaChange,\n}: {\n onSchemaChange?: (schema: JSONSchema7) => void;\n} = {}) {\n const context = useContext(SchemaContext);\n\n if (context === undefined) {\n throw new Error(\"useSchema must be used within a SchemaProvider\");\n }\n\n const { path, schema, setSchema } = context;\n\n /**\n * Navigates to the correct property schema of the latest key in the provided path.\n *\n * It will traverse both \"properties\" and \"items\" to find the correct property schema.\n *\n * It will only return a property schema if the provided path is valid i.e. it\n * correctly follows the schema's nesting structure.\n *\n * It will only return a parent schema if the provided path is valid i.e. it\n * correctly follows the schema's nesting structure.\n */\n const navigateToCorrectNesting = (\n providedSchema: JSONSchema7,\n providedPath: string[],\n ) => {\n let current = providedSchema;\n let propertySchema: JSONSchema7 | null = null;\n // Should be the schema of type \"object\" containing the property in its properties key\n let parentSchema: JSONSchema7 | null = null;\n\n for (const p of providedPath) {\n if (\n current.type === \"array\" &&\n current.items &&\n !Array.isArray(current.items) &&\n typeof current.items === \"object\" &&\n current.items.type === \"object\" &&\n typeof current.items.properties?.[p] === \"object\"\n ) {\n parentSchema = current.items;\n propertySchema = current.items.properties[p];\n current = current.items;\n } else if (\n current.type === \"object\" &&\n current.properties &&\n !Array.isArray(current.properties) &&\n typeof current.properties[p] === \"object\"\n ) {\n parentSchema = current;\n propertySchema = current.properties[p];\n current = current.properties[p];\n }\n }\n\n return { propertySchema, parentSchema };\n };\n\n /**\n * Gets the current schema of the latest key in the path.\n * If path is empty, it will return the root schema.\n *\n * It should always return the \"object\" schema of the current path.\n */\n const getCurrentSchema = (initialSchema?: JSONSchema7) => {\n // Gets the correct object schema if under nesting\n // Otherwise, return the root schema\n const { propertySchema } = navigateToCorrectNesting(\n initialSchema ?? schema,\n path,\n );\n\n if (propertySchema) {\n if (propertySchema.type === \"array\") {\n return propertySchema.items as JSONSchema7;\n }\n\n return propertySchema;\n }\n\n return initialSchema ?? schema;\n };\n\n /**\n * Gets the correct property schema of the latest key in the path.\n * If no path is provided, it will return null.\n */\n const getCurrentProperty = () => {\n const { propertySchema } = navigateToCorrectNesting(schema, path);\n\n return propertySchema;\n };\n\n /**\n * Change the key of a property in the schema. It expects\n * the find the key at the current path.\n */\n const handleKeyChange = (key: string, newKey: string) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to change\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n if (current.properties?.[key]) {\n //Important: maintain order as to not confuse users\n const newProperties = Object.entries(current.properties).map(\n ([k, val]) => {\n return [k === key ? newKey : k, val];\n },\n );\n\n current.properties = Object.fromEntries(\n newProperties,\n ) as JSONSchema7[\"properties\"];\n }\n\n if (current.required?.includes(key)) {\n current.required = current.required.map((item) =>\n item === key ? newKey : item,\n );\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n };\n\n const handlePropertyChange = (\n key: string,\n updates: Partial<JSONSchema7Definition> & { isRequired?: boolean },\n ): PropertyChangeSuccess | undefined => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to change\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Handle required field updates\n if (typeof updates === \"object\" && \"isRequired\" in updates) {\n if (current.type === \"object\") {\n if (!current.required) {\n current.required = [];\n }\n if (updates.isRequired) {\n if (!current.required.includes(key)) {\n current.required.push(key);\n }\n } else {\n current.required = current.required.filter((item) => item !== key);\n }\n }\n delete updates.isRequired;\n }\n\n let isUpdated = false;\n\n // Update the property\n if (current.type === \"object\" && current.properties) {\n const originalProperty = current.properties[key];\n // Ensure the property exists and is not a boolean\n if (typeof originalProperty !== \"boolean\" && originalProperty) {\n if (typeof updates !== \"boolean\") {\n //if updates changes the type of the property,\n //only the title, description, and default properties should remain\n //from the original property\n if (updates.type && updates.type !== originalProperty.type) {\n updates = {\n title: originalProperty.title,\n description: originalProperty.description,\n default: originalProperty.default,\n ...updates,\n };\n } else if (updates.enum) {\n //if the property is an enum, only the title and description should remain\n //from the original property\n delete updates.type;\n delete updates.items;\n delete updates.properties;\n updates = {\n title: originalProperty.title,\n description: originalProperty.description,\n ...updates,\n };\n } else {\n updates = { ...originalProperty, ...updates };\n }\n\n current.properties[key] = updates;\n }\n }\n isUpdated = true;\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n\n if (isUpdated) {\n return { status: \"success\", property: current.properties![key]! };\n }\n };\n\n /**\n * Adds a sibling property to the current schema.\n */\n const handleAddProperty = (\n key: string,\n propertyToAdd: JSONSchema7,\n isRequired: boolean,\n ) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to add\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Ensure the current schema has a properties object\n if (current.type !== \"object\") {\n current.type = \"object\";\n }\n if (!current.properties) {\n current.properties = {};\n }\n\n //Ensure there's no existing property with the same key\n if (current.properties[key]) {\n return {\n status: \"error\",\n code: \"key-exists\" as const,\n message: `Property with key ${key} already exists`,\n } satisfies PropertyAddError;\n }\n\n if (propertyToAdd.enum) {\n //ensure that only the enum property is present\n delete propertyToAdd.type;\n delete propertyToAdd.items;\n delete propertyToAdd.properties;\n }\n\n // Clean the propertyToAdd object ensuring it doesn't contain\n //keys with undefined values\n propertyToAdd = Object.fromEntries(\n Object.entries(propertyToAdd).filter(([, value]) => value !== undefined),\n );\n\n // Add the new property\n current.properties[key] = propertyToAdd;\n\n // Handle required field\n if (isRequired) {\n if (!current.required) {\n current.required = [];\n }\n if (!current.required.includes(key)) {\n current.required.push(key);\n }\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n\n return {\n status: \"success\" as const,\n property: current.properties[key],\n } satisfies PropertyAddSuccess;\n };\n\n const handleDeleteProperty = (key: string) => {\n const newSchema = clone(schema);\n\n // The current schema containing the property to delete\n const current: JSONSchema7 = getCurrentSchema(newSchema);\n\n // Handle required field updates\n if (current.type === \"object\") {\n if (current.required) {\n current.required = current.required.filter((item) => item !== key);\n }\n }\n\n // Delete the property\n if (current.type === \"object\" && current.properties) {\n delete current.properties[key];\n }\n\n setSchema(newSchema);\n onSchemaChange?.(newSchema);\n };\n\n const handleDuplicateProperty = (key: string) => {\n const currentProperties = getCurrentSchema().properties;\n if (\n !currentProperties ||\n isEmpty(currentProperties) ||\n typeof currentProperties[key] === \"boolean\"\n ) {\n return;\n }\n\n const propertyToDuplicate = currentProperties[key]!;\n const newKey = `${key}_copy`;\n const newProperty = clone(propertyToDuplicate);\n\n // Add the duplicated property\n return handleAddProperty(newKey, newProperty, isPropertyRequired(key));\n };\n\n const isPropertyRequired = (key: string) => {\n if (path.length) {\n const { propertySchema } = navigateToCorrectNesting(schema, path);\n\n if (\n propertySchema?.type === \"array\" &&\n propertySchema.items &&\n typeof propertySchema.items !== \"boolean\" &&\n !Array.isArray(propertySchema.items) &&\n propertySchema.items?.type === \"object\"\n ) {\n return Boolean(propertySchema.items?.required?.includes(key));\n } else {\n return Boolean(propertySchema?.required?.includes(key));\n }\n }\n\n return Boolean(schema?.required?.includes(key));\n };\n\n /**\n * Programatically get the current schema value\n */\n const getValue = () => {\n return schema;\n };\n\n return {\n ...context,\n getCurrentSchema,\n getCurrentProperty,\n handlePropertyChange,\n handleAddProperty,\n handleKeyChange,\n navigateToCorrectNesting,\n handleDeleteProperty,\n isPropertyRequired,\n getValue,\n handleDuplicateProperty,\n };\n}\n\nexport { SchemaProvider, useSchema };\n"],"names":["SchemaContext","createContext","defaultSchema","SchemaProvider","children","initialSchema","schema","setSchema","useState","path","setPath","jsx","useSchema","onSchemaChange","context","useContext","navigateToCorrectNesting","providedSchema","providedPath","current","propertySchema","parentSchema","p","getCurrentSchema","getCurrentProperty","handleKeyChange","key","newKey","newSchema","clone","newProperties","k","val","item","handlePropertyChange","updates","isUpdated","originalProperty","handleAddProperty","propertyToAdd","isRequired","value","handleDeleteProperty","handleDuplicateProperty","currentProperties","isEmpty","propertyToDuplicate","newProperty","isPropertyRequired"],"mappings":"mMAcaA,EAAgBC,gBAE3B,MAAS,EAELC,EAA6B,CACjC,QAAS,0CACT,KAAM,SACN,MAAO,QACP,YAAa,GACb,WAAY,CAAC,EACb,SAAU,CAAA,CACZ,EAEA,SAASC,EAAe,CACtB,SAAAC,EACA,cAAAC,CACF,EAAuD,CAC/C,KAAA,CAACC,EAAQC,CAAS,EAAIC,EAAA,SAC1BH,GAAiBH,CACnB,EAQM,CAACO,EAAMC,CAAO,EAAIF,EAAAA,SAAmB,CAAA,CAAE,EAM3C,OAAAG,MAACX,EAAc,SAAd,CAAuB,MAAO,CAAE,OAAAM,EAAQ,UAAAC,EAAW,KAAAE,EAAM,QAAAC,CAAQ,EAC/D,SAAAN,CACH,CAAA,CAEJ,CAgBA,SAASQ,EAAU,CACjB,eAAAC,CACF,EAEI,GAAI,CACA,MAAAC,EAAUC,aAAWf,CAAa,EAExC,GAAIc,IAAY,OACR,MAAA,IAAI,MAAM,gDAAgD,EAGlE,KAAM,CAAE,KAAAL,EAAM,OAAAH,EAAQ,UAAAC,CAAc,EAAAO,EAa9BE,EAA2B,CAC/BC,EACAC,IACG,CACH,IAAIC,EAAUF,EACVG,EAAqC,KAErCC,EAAmC,KAEvC,UAAWC,KAAKJ,EAEZC,EAAQ,OAAS,SACjBA,EAAQ,OACR,CAAC,MAAM,QAAQA,EAAQ,KAAK,GAC5B,OAAOA,EAAQ,OAAU,UACzBA,EAAQ,MAAM,OAAS,UACvB,OAAOA,EAAQ,MAAM,aAAaG,CAAC,GAAM,UAEzCD,EAAeF,EAAQ,MACNC,EAAAD,EAAQ,MAAM,WAAWG,CAAC,EAC3CH,EAAUA,EAAQ,OAElBA,EAAQ,OAAS,UACjBA,EAAQ,YACR,CAAC,MAAM,QAAQA,EAAQ,UAAU,GACjC,OAAOA,EAAQ,WAAWG,CAAC,GAAM,WAElBD,EAA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AU,EACA,kBAAAI,EACA,gBAAAb,EACA,yBAAAT,EACA,qBAAA0B,EACA,mBAAAM,EACA,SAde,IACR1C,EAcP,wBAAAqC,CACF,CACF"}
|
package/dist/index.cjs21.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),N=require("./index.cjs11.js"),R=require("./index.cjs44.js"),m=require("./index.cjs41.js"),E=require("./index.cjs28.js"),L=require("./index.cjs15.js"),a=require("./index.cjs14.js"),k=require("./index.cjs13.js"),v=require("./index.cjs20.js"),h=require("./index.cjs10.js"),w=require("./index.cjs46.js"),M=require("./index.cjs4.js"),P=require("./index.cjs42.js"),$=require("./index.cjs43.js"),o=require("zod"),B=require("react-hook-form"),t=require("./index.cjs45.js"),d=o.z.enum(["string","number","integer","boolean","object","array","null"]),b=o.z.object({key:o.z.string().trim().min(1,{message:"Key must be at least 1 character long"}),property:o.z.object({title:o.z.string().trim().min(1,{message:"Title must be at least 1 character long"}),type:d.or(o.z.array(d)),description:o.z.string().optional(),enum:o.z.array(o.z.string().or(o.z.number()).or(o.z.null()).or(o.z.boolean()).or(o.z.record(o.z.string(),o.z.any()))).optional(),items:o.z.object({type:d.or(o.z.array(d))}).or(o.z.array(o.z.object({type:d.or(o.z.array(d))}).or(o.z.boolean()))).or(o.z.boolean()).optional()}),required:o.z.boolean().default(!1),constraints:o.z.array(o.z.custom(()=>({name:o.z.string().trim().min(1),value:o.z.any()}))).optional()});function _({open:F,onOpenChange:C,onSubmit:S}){const n=B.useForm({resolver:R.zodResolver(b),defaultValues:{key:"",property:{title:""}}}),p=n.watch("constraints"),y=n.watch("property"),z=n.watch("property.enum"),I=n.watch("property.type"),{getConstraintDefinitionsForType:f,getRendererForConstraint:q,validateConstraintValue:D}=M.useConstraints(),A=r=>{const{key:s,property:l,required:c,constraints:i}=r,u={...l,...i?.reduce((j,g)=>({...j,[g.name]:g.value}),{})};S(s,u,c),n.reset()},V=(r,s)=>{const l=h.a(p),c=l?.[r];if(!c){n.setError(`constraints.${r}`,{message:"The constraint was not found",type:"constraint_not_found"});return}const i=D(c.name,s);if(i.status==="error"){let u=i.message;i.code==="invalid"&&(u=`${u}: ${i.error?.map(j=>j.message).join(", ")}`),n.setError(`constraints.${r}`,{type:i.code,message:u});return}c.value=s,n.setValue("constraints",l),n.clearErrors(`constraints.${r}`)},T=r=>{if(!p)return;const l=h.a(p).filter(c=>c.name!==r);n.setValue("constraints",l)},x=f(typeof y?.type=="string"?y.type:"");return e.jsx(m.Dialog,{open:F,onOpenChange:C,children:e.jsxs(m.DialogContent,{"data-testid":"add-property-dialog",children:[e.jsxs(m.DialogHeader,{children:[e.jsx(m.DialogTitle,{children:"Add"}),e.jsx(m.DialogDescription,{children:"Required property values and constraints"})]}),e.jsx(t.Form,{...n,children:e.jsxs("form",{onSubmit:n.handleSubmit(A),className:"space-y-4","data-testid":"add-property-form",children:[e.jsx("div",{className:"space-y-2",children:e.jsx(t.FormField,{control:n.control,name:"key",render:({field:r})=>{const{onChange:s,...l}=r;return e.jsxs(t.FormItem,{children:[e.jsx(t.FormLabel,{children:"Property Key"}),e.jsx(t.FormControl,{children:e.jsx(v.DebouncedInput,{...l,onDebounce:c=>s(c)})}),e.jsx(t.FormMessage,{})]})}})}),e.jsx("div",{className:"space-y-2",children:e.jsx(t.FormField,{control:n.control,name:"property.title",render:({field:r})=>{const{onChange:s,...l}=r;return e.jsxs(t.FormItem,{children:[e.jsx(t.FormLabel,{children:"Property Title"}),e.jsx(t.FormControl,{children:e.jsx(v.DebouncedInput,{...l,onDebounce:c=>s(c)})}),e.jsx(t.FormMessage,{})]})}})}),e.jsx("div",{className:"space-y-2",children:e.jsx(t.FormField,{control:n.control,name:"property.type",render:({field:r})=>e.jsxs(t.FormItem,{children:[e.jsx(t.FormLabel,{children:"Type"}),e.jsx(t.FormControl,{children:e.jsxs(a.Select,{value:Array.isArray(r.value)?void 0:r.value,onValueChange:s=>{s==="enum"?n.setValue("property.enum",[]):n.setValue("property.enum",void 0),r.value==="array"&&s!=="array"&&(n.clearErrors("property.items"),n.setValue("property.items",void 0)),r.onChange(s)},children:[e.jsx(a.SelectTrigger,{className:"w-full","aria-label":"Select type",children:e.jsx(a.SelectValue,{})}),e.jsxs(a.SelectContent,{children:[e.jsx(a.SelectItem,{value:"string",children:"string"}),e.jsx(a.SelectItem,{value:"number",children:"number"}),e.jsx(a.SelectItem,{value:"integer",children:"integer"}),e.jsx(a.SelectItem,{value:"boolean",children:"boolean"}),e.jsx(a.SelectItem,{value:"object",children:"object"}),e.jsx(a.SelectItem,{value:"array",children:"array"}),e.jsx(a.SelectItem,{value:"null",children:"null"})]})]})}),e.jsx(t.FormMessage,{})]})})}),I==="array"&&e.jsx("div",{className:"space-y-2",children:e.jsx(t.FormField,{control:n.control,name:"property.items.type",render:({field:r})=>e.jsxs(t.FormItem,{children:[e.jsx(t.FormLabel,{children:"Items of type"}),e.jsx(t.FormControl,{children:e.jsxs(a.Select,{value:Array.isArray(r.value)?void 0:r.value,onValueChange:s=>{n.clearErrors("property.items.type"),n.setValue("property.items.type",s)},children:[e.jsx(a.SelectTrigger,{className:"w-full","aria-label":"Select items of type",children:e.jsx(a.SelectValue,{placeholder:"Select item type"})}),e.jsxs(a.SelectContent,{children:[e.jsx(a.SelectItem,{value:"string",children:"string"}),e.jsx(a.SelectItem,{value:"number",children:"number"}),e.jsx(a.SelectItem,{value:"integer",children:"integer"}),e.jsx(a.SelectItem,{value:"boolean",children:"boolean"}),e.jsx(a.SelectItem,{value:"object",children:"object"}),e.jsx(a.SelectItem,{value:"array",children:"array"}),e.jsx(a.SelectItem,{value:"null",children:"null"})]})]})}),e.jsx(t.FormMessage,{})]})})}),e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(t.FormField,{control:n.control,name:"required",render:({field:r})=>e.jsxs(t.FormItem,{children:[e.jsx(t.FormControl,{children:e.jsx(k.Switch,{checked:r.value,onCheckedChange:s=>r.onChange(s)})}),e.jsx(t.FormLabel,{children:"Required"}),e.jsx(t.FormMessage,{})]})})}),e.jsx("div",{className:"space-y-2",children:e.jsx(t.FormField,{control:n.control,name:"property.description",render:({field:r})=>e.jsxs(t.FormItem,{children:[e.jsx(t.FormLabel,{children:"Description"}),e.jsx(t.FormControl,{children:e.jsx(E.Input,{...r})}),e.jsx(t.FormMessage,{})]})})}),z?e.jsx(t.FormField,{control:n.control,name:"property.enum",render:({field:r})=>e.jsxs(t.FormItem,{children:[e.jsx(t.FormLabel,{children:"Enum"}),e.jsx(t.FormControl,{children:e.jsx(w.default,{values:r.value?.filter(s=>typeof s=="string")??[],onAddValue:s=>{const l=[];r.value&&l.push(...r.value),l.push(s),r.onChange(l)},onRemoveValue:s=>{const l=h.a(r.value??[]);l.splice(s,1),r.onChange(l)}})}),e.jsx(t.FormMessage,{})]})}):null,x.length?e.jsxs("div",{className:"space-y-2",children:[e.jsx(L.Label,{children:"Constraints"}),e.jsx(P.default,{addedConstraints:p??[],availableDefinitions:x,onAdd:r=>{n.setValue("constraints",r)}}),e.jsx($.Separator,{}),p?.map((r,s)=>{const l=q(r.name);if(!l)return null;const c=n.formState.errors.constraints?.[s];let i;return c&&(i={code:c?.type??"INVALID",message:c.message??"An error occurred"}),e.jsx(l,{constraintName:r.name,value:r.value,onConstraintChange:u=>{V(s,u)},onRemoveConstraint:()=>{T(r.name)},error:i},r.name)})]}):null,e.jsx(m.DialogFooter,{children:e.jsx(N.Button,{type:"submit",children:"Add Property"})})]})})]})})}exports.AddFormSchema=b;exports.AddPropertyDialog=_;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),N=require("./index.cjs11.js"),R=require("./index.cjs44.js"),m=require("./index.cjs41.js"),E=require("./index.cjs28.js"),L=require("./index.cjs15.js"),a=require("./index.cjs14.js"),k=require("./index.cjs13.js"),v=require("./index.cjs20.js"),h=require("./index.cjs10.js"),w=require("./index.cjs46.js"),M=require("./index.cjs4.js"),P=require("./index.cjs42.js"),$=require("./index.cjs43.js"),o=require("zod"),B=require("react-hook-form"),t=require("./index.cjs45.js"),d=o.z.enum(["string","number","integer","boolean","object","array","null"]),b=o.z.object({key:o.z.string().trim().min(1,{message:"Key must be at least 1 character long"}),property:o.z.object({title:o.z.string().trim().min(1,{message:"Title must be at least 1 character long"}),type:d.or(o.z.array(d)),description:o.z.string().optional(),enum:o.z.array(o.z.string().or(o.z.number()).or(o.z.null()).or(o.z.boolean()).or(o.z.record(o.z.string(),o.z.any()))).optional(),items:o.z.object({type:d.or(o.z.array(d))}).or(o.z.array(o.z.object({type:d.or(o.z.array(d))}).or(o.z.boolean()))).or(o.z.boolean()).optional()}),required:o.z.boolean().default(!1),constraints:o.z.array(o.z.custom(()=>({name:o.z.string().trim().min(1),value:o.z.any()}))).optional()});function _({open:F,onOpenChange:C,onSubmit:S}){const n=B.useForm({resolver:R.zodResolver(b),defaultValues:{key:"",property:{title:""}}}),p=n.watch("constraints"),y=n.watch("property"),z=n.watch("property.enum"),I=n.watch("property.type"),{getConstraintDefinitionsForType:f,getRendererForConstraint:q,validateConstraintValue:D}=M.useConstraints(),A=r=>{const{key:s,property:l,required:c,constraints:i}=r,u={...l,...i?.reduce((j,g)=>({...j,[g.name]:g.value}),{})};S(s,u,c),n.reset()},V=(r,s)=>{const l=h.a(p),c=l?.[r];if(!c){n.setError(`constraints.${r}`,{message:"The constraint was not found",type:"constraint_not_found"});return}const i=D(c.name,s);if(i.status==="error"){let u=i.message;i.code==="invalid"&&(u=`${u}: ${i.error?.map(j=>j.message).join(", ")}`),n.setError(`constraints.${r}`,{type:i.code,message:u});return}c.value=s,n.setValue("constraints",l),n.clearErrors(`constraints.${r}`)},T=r=>{if(!p)return;const l=h.a(p).filter(c=>c.name!==r);n.setValue("constraints",l)},x=f(typeof y?.type=="string"?y.type:"");return e.jsx(m.Dialog,{open:F,onOpenChange:C,children:e.jsxs(m.DialogContent,{"data-testid":"add-property-dialog",children:[e.jsxs(m.DialogHeader,{children:[e.jsx(m.DialogTitle,{children:"Add"}),e.jsx(m.DialogDescription,{children:"Required property values and constraints"})]}),e.jsx(t.Form,{...n,children:e.jsxs("form",{onSubmit:r=>{r.stopPropagation(),r.preventDefault(),n.handleSubmit(A)(r)},className:"space-y-4","data-testid":"add-property-form",id:"add-property-form",children:[e.jsx("div",{className:"space-y-2",children:e.jsx(t.FormField,{control:n.control,name:"key",render:({field:r})=>{const{onChange:s,...l}=r;return e.jsxs(t.FormItem,{children:[e.jsx(t.FormLabel,{children:"Property Key"}),e.jsx(t.FormControl,{children:e.jsx(v.DebouncedInput,{...l,onDebounce:c=>s(c)})}),e.jsx(t.FormMessage,{})]})}})}),e.jsx("div",{className:"space-y-2",children:e.jsx(t.FormField,{control:n.control,name:"property.title",render:({field:r})=>{const{onChange:s,...l}=r;return e.jsxs(t.FormItem,{children:[e.jsx(t.FormLabel,{children:"Property Title"}),e.jsx(t.FormControl,{children:e.jsx(v.DebouncedInput,{...l,onDebounce:c=>s(c)})}),e.jsx(t.FormMessage,{})]})}})}),e.jsx("div",{className:"space-y-2",children:e.jsx(t.FormField,{control:n.control,name:"property.type",render:({field:r})=>e.jsxs(t.FormItem,{children:[e.jsx(t.FormLabel,{children:"Type"}),e.jsx(t.FormControl,{children:e.jsxs(a.Select,{value:Array.isArray(r.value)?void 0:r.value,onValueChange:s=>{s==="enum"?n.setValue("property.enum",[]):n.setValue("property.enum",void 0),r.value==="array"&&s!=="array"&&(n.clearErrors("property.items"),n.setValue("property.items",void 0)),r.onChange(s)},children:[e.jsx(a.SelectTrigger,{className:"w-full","aria-label":"Select type",children:e.jsx(a.SelectValue,{})}),e.jsxs(a.SelectContent,{children:[e.jsx(a.SelectItem,{value:"string",children:"string"}),e.jsx(a.SelectItem,{value:"number",children:"number"}),e.jsx(a.SelectItem,{value:"integer",children:"integer"}),e.jsx(a.SelectItem,{value:"boolean",children:"boolean"}),e.jsx(a.SelectItem,{value:"object",children:"object"}),e.jsx(a.SelectItem,{value:"array",children:"array"}),e.jsx(a.SelectItem,{value:"null",children:"null"})]})]})}),e.jsx(t.FormMessage,{})]})})}),I==="array"&&e.jsx("div",{className:"space-y-2",children:e.jsx(t.FormField,{control:n.control,name:"property.items.type",render:({field:r})=>e.jsxs(t.FormItem,{children:[e.jsx(t.FormLabel,{children:"Items of type"}),e.jsx(t.FormControl,{children:e.jsxs(a.Select,{value:Array.isArray(r.value)?void 0:r.value,onValueChange:s=>{n.clearErrors("property.items.type"),n.setValue("property.items.type",s)},children:[e.jsx(a.SelectTrigger,{className:"w-full","aria-label":"Select items of type",children:e.jsx(a.SelectValue,{placeholder:"Select item type"})}),e.jsxs(a.SelectContent,{children:[e.jsx(a.SelectItem,{value:"string",children:"string"}),e.jsx(a.SelectItem,{value:"number",children:"number"}),e.jsx(a.SelectItem,{value:"integer",children:"integer"}),e.jsx(a.SelectItem,{value:"boolean",children:"boolean"}),e.jsx(a.SelectItem,{value:"object",children:"object"}),e.jsx(a.SelectItem,{value:"array",children:"array"}),e.jsx(a.SelectItem,{value:"null",children:"null"})]})]})}),e.jsx(t.FormMessage,{})]})})}),e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(t.FormField,{control:n.control,name:"required",render:({field:r})=>e.jsxs(t.FormItem,{children:[e.jsx(t.FormControl,{children:e.jsx(k.Switch,{checked:r.value,onCheckedChange:s=>r.onChange(s)})}),e.jsx(t.FormLabel,{children:"Required"}),e.jsx(t.FormMessage,{})]})})}),e.jsx("div",{className:"space-y-2",children:e.jsx(t.FormField,{control:n.control,name:"property.description",render:({field:r})=>e.jsxs(t.FormItem,{children:[e.jsx(t.FormLabel,{children:"Description"}),e.jsx(t.FormControl,{children:e.jsx(E.Input,{...r})}),e.jsx(t.FormMessage,{})]})})}),z?e.jsx(t.FormField,{control:n.control,name:"property.enum",render:({field:r})=>e.jsxs(t.FormItem,{children:[e.jsx(t.FormLabel,{children:"Enum"}),e.jsx(t.FormControl,{children:e.jsx(w.default,{values:r.value?.filter(s=>typeof s=="string")??[],onAddValue:s=>{const l=[];r.value&&l.push(...r.value),l.push(s),r.onChange(l)},onRemoveValue:s=>{const l=h.a(r.value??[]);l.splice(s,1),r.onChange(l)}})}),e.jsx(t.FormMessage,{})]})}):null,x.length?e.jsxs("div",{className:"space-y-2",children:[e.jsx(L.Label,{children:"Constraints"}),e.jsx(P.default,{addedConstraints:p??[],availableDefinitions:x,onAdd:r=>{n.setValue("constraints",r)}}),e.jsx($.Separator,{}),p?.map((r,s)=>{const l=q(r.name);if(!l)return null;const c=n.formState.errors.constraints?.[s];let i;return c&&(i={code:c?.type??"INVALID",message:c.message??"An error occurred"}),e.jsx(l,{constraintName:r.name,value:r.value,onConstraintChange:u=>{V(s,u)},onRemoveConstraint:()=>{T(r.name)},error:i},r.name)})]}):null,e.jsx(m.DialogFooter,{children:e.jsx(N.Button,{type:"submit",form:"add-property-form",children:"Add Property"})})]})})]})})}exports.AddFormSchema=b;exports.AddPropertyDialog=_;
|
|
2
2
|
//# sourceMappingURL=index.cjs21.js.map
|
package/dist/index.cjs21.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs21.js","sources":["../src/packages/builder/add-dialog.tsx"],"sourcesContent":["import { Button } from \"@/components/ui/button\";\nimport { zodResolver } from \"@hookform/resolvers/zod\";\n\nimport {\n Dialog,\n DialogContent,\n DialogHeader,\n DialogTitle,\n DialogFooter,\n DialogDescription,\n} from \"@/components/ui/dialog\";\nimport { Input } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport {\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from \"@/components/ui/select\";\nimport { Switch } from \"@/components/ui/switch\";\nimport type { JSONSchema7, JSONSchema7TypeName } from \"json-schema\";\nimport { DebouncedInput } from \"@/components/depounced-input\";\nimport { clone } from \"remeda\";\nimport MultiInput from \"@/components/multi-input\";\nimport { Constraint, useConstraints } from \"@/packages/constraints/context\";\nimport ConstraintsAdd from \"@/packages/constraints/constraint-add\";\nimport { Separator } from \"@/components/ui/separator\";\nimport { z } from \"zod\";\nimport { useForm } from \"react-hook-form\";\nimport {\n Form,\n FormControl,\n FormField,\n FormItem,\n FormLabel,\n FormMessage,\n} from \"@/components/ui/form\";\nimport type { OperationError } from \"./shared-types\";\n\nexport interface AddPropertyDialogProps {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n onSubmit: (key: string, property: JSONSchema7, required: boolean) => void;\n}\n\nconst zodJsonTypes = z.enum([\n \"string\",\n \"number\",\n \"integer\",\n \"boolean\",\n \"object\",\n \"array\",\n \"null\",\n]);\n\nexport const AddFormSchema = z.object({\n key: z\n .string()\n .trim()\n .min(1, { message: \"Key must be at least 1 character long\" }),\n property: z.object({\n title: z\n .string()\n .trim()\n .min(1, { message: \"Title must be at least 1 character long\" }),\n type: zodJsonTypes.or(z.array(zodJsonTypes)),\n description: z.string().optional(),\n enum: z\n .array(\n z\n .string()\n .or(z.number())\n .or(z.null())\n .or(z.boolean())\n .or(z.record(z.string(), z.any())),\n )\n .optional(),\n items: z\n .object({\n type: zodJsonTypes.or(z.array(zodJsonTypes)),\n })\n //only to satisfy the other types but we actually don't handle it\n .or(\n z.array(\n z\n .object({ type: zodJsonTypes.or(z.array(zodJsonTypes)) })\n .or(z.boolean()),\n ),\n )\n .or(z.boolean())\n .optional(),\n }),\n required: z.boolean().default(false),\n constraints: z\n .array(\n z.custom<Constraint>(() => ({\n name: z.string().trim().min(1),\n value: z.any(),\n })),\n )\n .optional(),\n});\n\n/**\n * Handles adding a property to a parent JSON schema's \"properties\".\n * This means you are working under a child property.\n */\nexport function AddPropertyDialog({\n open,\n onOpenChange,\n onSubmit,\n}: AddPropertyDialogProps) {\n const form = useForm<z.infer<typeof AddFormSchema>>({\n resolver: zodResolver(AddFormSchema),\n defaultValues: {\n key: \"\",\n property: {\n title: \"\",\n },\n },\n });\n\n const currentConstraints = form.watch(\"constraints\");\n const currentProperty = form.watch(\"property\");\n const currentEnum = form.watch(\"property.enum\");\n const currentType = form.watch(\"property.type\");\n\n const {\n getConstraintDefinitionsForType,\n getRendererForConstraint,\n validateConstraintValue,\n } = useConstraints();\n\n const handleSubmit = (data: z.infer<typeof AddFormSchema>) => {\n const { key, property, required, constraints } = data;\n const propertyToSubmit: JSONSchema7 = {\n ...property,\n ...constraints?.reduce((acc, constraint) => {\n return {\n ...acc,\n [constraint.name]: constraint.value,\n } satisfies JSONSchema7;\n }, {}),\n };\n onSubmit(key, propertyToSubmit, required);\n form.reset();\n };\n\n const handleConstraintChange = (\n index: number,\n newVal: Constraint[\"value\"],\n ) => {\n const constraintsCopy = clone(currentConstraints);\n\n const constraintToChange = constraintsCopy?.[index];\n\n if (!constraintToChange) {\n form.setError(`constraints.${index}`, {\n message: \"The constraint was not found\",\n type: \"constraint_not_found\",\n });\n return;\n }\n\n const validationResult = validateConstraintValue(\n constraintToChange.name,\n newVal,\n );\n\n if (validationResult.status === \"error\") {\n let message = validationResult.message;\n if (validationResult.code === \"invalid\") {\n message = `${message}: ${validationResult.error?.map((i) => i.message).join(\", \")}`;\n }\n form.setError(`constraints.${index}`, {\n type: validationResult.code,\n message,\n });\n return;\n }\n\n //edit reference\n constraintToChange.value = newVal;\n form.setValue(\"constraints\", constraintsCopy);\n form.clearErrors(`constraints.${index}`);\n };\n\n const handleRemoveConstraint = (constraintName: Constraint[\"name\"]) => {\n if (!currentConstraints) return;\n const copy = clone(currentConstraints);\n const newConstraints = copy.filter((c) => c.name !== constraintName);\n form.setValue(\"constraints\", newConstraints);\n };\n\n const availableDefinitions = getConstraintDefinitionsForType(\n typeof currentProperty?.type === \"string\" ? currentProperty.type : \"\",\n );\n\n return (\n <Dialog open={open} onOpenChange={onOpenChange}>\n <DialogContent data-testid=\"add-property-dialog\">\n <DialogHeader>\n <DialogTitle>Add</DialogTitle>\n <DialogDescription>\n Required property values and constraints\n </DialogDescription>\n </DialogHeader>\n <Form {...form}>\n <form\n onSubmit={form.handleSubmit(handleSubmit)}\n className=\"space-y-4\"\n data-testid=\"add-property-form\"\n >\n <div className=\"space-y-2\">\n <FormField\n control={form.control}\n name=\"key\"\n render={({ field }) => {\n // Pull the onChange since debounced input should\n // be calling onDebounce instead\n const { onChange, ...rest } = field;\n\n return (\n <FormItem>\n <FormLabel>Property Key</FormLabel>\n <FormControl>\n <DebouncedInput\n {...rest}\n onDebounce={(newVal) => onChange(newVal)}\n />\n </FormControl>\n <FormMessage />\n </FormItem>\n );\n }}\n />\n </div>\n <div className=\"space-y-2\">\n <FormField\n control={form.control}\n name=\"property.title\"\n render={({ field }) => {\n const { onChange, ...rest } = field;\n return (\n <FormItem>\n <FormLabel>Property Title</FormLabel>\n <FormControl>\n <DebouncedInput\n {...rest}\n onDebounce={(newVal) => onChange(newVal)}\n />\n </FormControl>\n <FormMessage />\n </FormItem>\n );\n }}\n />\n </div>\n <div className=\"space-y-2\">\n <FormField\n control={form.control}\n name=\"property.type\"\n render={({ field }) => {\n return (\n <FormItem>\n <FormLabel>Type</FormLabel>\n <FormControl>\n <Select\n value={\n !Array.isArray(field.value)\n ? field.value\n : undefined\n }\n onValueChange={(newVal) => {\n if (newVal === \"enum\") {\n form.setValue(\"property.enum\", []);\n } else {\n form.setValue(\"property.enum\", undefined);\n }\n\n // If changing away from array, clear any array item errors\n if (field.value === \"array\" && newVal !== \"array\") {\n form.clearErrors(\"property.items\");\n form.setValue(\"property.items\", undefined);\n }\n\n field.onChange(newVal);\n }}\n >\n <SelectTrigger\n className=\"w-full\"\n aria-label=\"Select type\"\n >\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n <SelectItem\n value={\"string\" satisfies JSONSchema7TypeName}\n >\n string\n </SelectItem>\n <SelectItem\n value={\"number\" satisfies JSONSchema7TypeName}\n >\n number\n </SelectItem>\n <SelectItem\n value={\"integer\" satisfies JSONSchema7TypeName}\n >\n integer\n </SelectItem>\n <SelectItem\n value={\"boolean\" satisfies JSONSchema7TypeName}\n >\n boolean\n </SelectItem>\n <SelectItem\n value={\"object\" satisfies JSONSchema7TypeName}\n >\n object\n </SelectItem>\n <SelectItem\n value={\"array\" satisfies JSONSchema7TypeName}\n >\n array\n </SelectItem>\n <SelectItem\n value={\"null\" satisfies JSONSchema7TypeName}\n >\n null\n </SelectItem>\n </SelectContent>\n </Select>\n </FormControl>\n <FormMessage />\n </FormItem>\n );\n }}\n />\n </div>\n\n {/* Array Items Type selector */}\n {currentType === \"array\" && (\n <div className=\"space-y-2\">\n <FormField\n control={form.control}\n name=\"property.items.type\"\n render={({ field }) => {\n return (\n <FormItem>\n <FormLabel>Items of type</FormLabel>\n <FormControl>\n <Select\n value={\n !Array.isArray(field.value)\n ? field.value\n : undefined\n }\n onValueChange={(newVal) => {\n form.clearErrors(\"property.items.type\");\n form.setValue(\n \"property.items.type\",\n newVal as JSONSchema7TypeName,\n );\n }}\n >\n <SelectTrigger\n className=\"w-full\"\n aria-label=\"Select items of type\"\n >\n <SelectValue placeholder=\"Select item type\" />\n </SelectTrigger>\n <SelectContent>\n <SelectItem\n value={\"string\" satisfies JSONSchema7TypeName}\n >\n string\n </SelectItem>\n <SelectItem\n value={\"number\" satisfies JSONSchema7TypeName}\n >\n number\n </SelectItem>\n <SelectItem\n value={\"integer\" satisfies JSONSchema7TypeName}\n >\n integer\n </SelectItem>\n <SelectItem\n value={\"boolean\" satisfies JSONSchema7TypeName}\n >\n boolean\n </SelectItem>\n <SelectItem\n value={\"object\" satisfies JSONSchema7TypeName}\n >\n object\n </SelectItem>\n <SelectItem\n value={\"array\" satisfies JSONSchema7TypeName}\n >\n array\n </SelectItem>\n <SelectItem\n value={\"null\" satisfies JSONSchema7TypeName}\n >\n null\n </SelectItem>\n </SelectContent>\n </Select>\n </FormControl>\n <FormMessage />\n </FormItem>\n );\n }}\n />\n </div>\n )}\n\n <div className=\"flex items-center space-x-2\">\n <FormField\n control={form.control}\n name=\"required\"\n render={({ field }) => {\n return (\n <FormItem>\n <FormControl>\n <Switch\n checked={field.value}\n onCheckedChange={(checked) => field.onChange(checked)}\n />\n </FormControl>\n <FormLabel>Required</FormLabel>\n <FormMessage />\n </FormItem>\n );\n }}\n />\n </div>\n <div className=\"space-y-2\">\n <FormField\n control={form.control}\n name=\"property.description\"\n render={({ field }) => {\n return (\n <FormItem>\n <FormLabel>Description</FormLabel>\n <FormControl>\n <Input {...field} />\n </FormControl>\n <FormMessage />\n </FormItem>\n );\n }}\n />\n </div>\n {currentEnum ? (\n <FormField\n control={form.control}\n name=\"property.enum\"\n render={({ field }) => {\n return (\n <FormItem>\n <FormLabel>Enum</FormLabel>\n <FormControl>\n <MultiInput\n values={\n field.value?.filter((i) => typeof i === \"string\") ??\n []\n }\n onAddValue={(newVal) => {\n const updates = [];\n if (field.value) {\n updates.push(...field.value);\n }\n updates.push(newVal);\n field.onChange(updates);\n }}\n onRemoveValue={(index) => {\n const newEnums = clone(field.value ?? []);\n newEnums.splice(index, 1);\n field.onChange(newEnums);\n }}\n />\n </FormControl>\n <FormMessage />\n </FormItem>\n );\n }}\n />\n ) : null}\n\n {availableDefinitions.length ? (\n <div className=\"space-y-2\">\n <Label>Constraints</Label>\n <ConstraintsAdd\n addedConstraints={currentConstraints ?? []}\n availableDefinitions={availableDefinitions}\n onAdd={(newConstraints) => {\n form.setValue(\"constraints\", newConstraints);\n }}\n />\n <Separator />\n {currentConstraints?.map((constraint, i) => {\n const Renderer = getRendererForConstraint(constraint.name);\n if (!Renderer) return null;\n\n const error = form.formState.errors.constraints?.[i];\n let mappedError: OperationError | undefined;\n\n if (error) {\n mappedError = {\n code: error?.type ?? \"INVALID\",\n message: error.message ?? \"An error occurred\",\n };\n }\n\n return (\n <Renderer\n key={constraint.name}\n constraintName={constraint.name}\n value={constraint.value}\n onConstraintChange={(newVal) => {\n handleConstraintChange(i, newVal);\n }}\n onRemoveConstraint={() => {\n handleRemoveConstraint(constraint.name);\n }}\n error={mappedError}\n />\n );\n })}\n </div>\n ) : null}\n\n <DialogFooter>\n <Button type=\"submit\">Add Property</Button>\n </DialogFooter>\n </form>\n </Form>\n </DialogContent>\n </Dialog>\n );\n}\n"],"names":["zodJsonTypes","z","AddFormSchema","AddPropertyDialog","open","onOpenChange","onSubmit","form","useForm","zodResolver","currentConstraints","currentProperty","currentEnum","currentType","getConstraintDefinitionsForType","getRendererForConstraint","validateConstraintValue","useConstraints","handleSubmit","data","key","property","required","constraints","propertyToSubmit","acc","constraint","handleConstraintChange","index","newVal","constraintsCopy","clone","constraintToChange","validationResult","message","i","handleRemoveConstraint","constraintName","newConstraints","availableDefinitions","Dialog","jsxs","DialogContent","DialogHeader","jsx","DialogTitle","DialogDescription","Form","FormField","field","onChange","rest","FormItem","FormLabel","FormControl","DebouncedInput","FormMessage","Select","SelectTrigger","SelectValue","SelectContent","SelectItem","Switch","checked","Input","MultiInput","updates","newEnums","Label","ConstraintsAdd","Separator","Renderer","error","mappedError","DialogFooter","Button"],"mappings":"skBA8CMA,EAAeC,IAAE,KAAK,CAC1B,SACA,SACA,UACA,UACA,SACA,QACA,MACF,CAAC,EAEYC,EAAgBD,IAAE,OAAO,CACpC,IAAKA,EAAAA,EACF,OAAA,EACA,KAAA,EACA,IAAI,EAAG,CAAE,QAAS,wCAAyC,EAC9D,SAAUA,IAAE,OAAO,CACjB,MAAOA,EAAAA,EACJ,OAAA,EACA,KAAA,EACA,IAAI,EAAG,CAAE,QAAS,0CAA2C,EAChE,KAAMD,EAAa,GAAGC,EAAE,EAAA,MAAMD,CAAY,CAAC,EAC3C,YAAaC,EAAA,EAAE,OAAO,EAAE,SAAS,EACjC,KAAMA,EACH,EAAA,MACCA,EAAAA,EACG,OAAO,EACP,GAAGA,IAAE,QAAQ,EACb,GAAGA,EAAAA,EAAE,KAAA,CAAM,EACX,GAAGA,EAAA,EAAE,QAAS,CAAA,EACd,GAAGA,IAAE,OAAOA,EAAE,EAAA,OAAU,EAAAA,IAAE,KAAK,CAAC,GAEpC,SAAS,EACZ,MAAOA,IACJ,OAAO,CACN,KAAMD,EAAa,GAAGC,EAAAA,EAAE,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,EAAA,QAAA,CACC,iBAAkB3D,GAAsB,CAAC,EACzC,qBAAA6B,EACA,MAAQD,GAAmB,CACpB/B,EAAA,SAAS,cAAe+B,CAAc,CAAA,CAC7C,CACF,QACCgC,EAAU,UAAA,EAAA,EACV5D,GAAoB,IAAI,CAACgB,EAAYS,IAAM,CACpC,MAAAoC,EAAWxD,EAAyBW,EAAW,IAAI,EACrD,GAAA,CAAC6C,EAAiB,OAAA,KAEtB,MAAMC,EAAQjE,EAAK,UAAU,OAAO,cAAc4B,CAAC,EAC/C,IAAAsC,EAEJ,OAAID,IACYC,EAAA,CACZ,KAAMD,GAAO,MAAQ,UACrB,QAASA,EAAM,SAAW,mBAC5B,GAIA5B,EAAA,IAAC2B,EAAA,CAEC,eAAgB7C,EAAW,KAC3B,MAAOA,EAAW,MAClB,mBAAqBG,GAAW,CAC9BF,EAAuBQ,EAAGN,CAAM,CAClC,EACA,mBAAoB,IAAM,CACxBO,EAAuBV,EAAW,IAAI,CACxC,EACA,MAAO+C,CAAA,EATF/C,EAAW,IAUlB,CAEH,CAAA,CAAA,CAAA,CACH,EACE,WAEHgD,EACC,aAAA,CAAA,SAAA9B,MAAC+B,EAAAA,QAAO,KAAK,SAAS,uBAAY,CAAA,CACpC,CAAA,CAAA,CAAA,CAAA,CAEJ,CAAA,CAAA,CAAA,CACF,CACF,CAAA,CAEJ"}
|
|
1
|
+
{"version":3,"file":"index.cjs21.js","sources":["../src/packages/builder/add-dialog.tsx"],"sourcesContent":["import { Button } from \"@/components/ui/button\";\nimport { zodResolver } from \"@hookform/resolvers/zod\";\n\nimport {\n Dialog,\n DialogContent,\n DialogHeader,\n DialogTitle,\n DialogFooter,\n DialogDescription,\n} from \"@/components/ui/dialog\";\nimport { Input } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport {\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from \"@/components/ui/select\";\nimport { Switch } from \"@/components/ui/switch\";\nimport type { JSONSchema7, JSONSchema7TypeName } from \"json-schema\";\nimport { DebouncedInput } from \"@/components/depounced-input\";\nimport { clone } from \"remeda\";\nimport MultiInput from \"@/components/multi-input\";\nimport { Constraint, useConstraints } from \"@/packages/constraints/context\";\nimport ConstraintsAdd from \"@/packages/constraints/constraint-add\";\nimport { Separator } from \"@/components/ui/separator\";\nimport { z } from \"zod\";\nimport { useForm } from \"react-hook-form\";\nimport {\n Form,\n FormControl,\n FormField,\n FormItem,\n FormLabel,\n FormMessage,\n} from \"@/components/ui/form\";\nimport type { OperationError } from \"./shared-types\";\n\nexport interface AddPropertyDialogProps {\n open: boolean;\n onOpenChange: (open: boolean) => void;\n onSubmit: (key: string, property: JSONSchema7, required: boolean) => void;\n}\n\nconst zodJsonTypes = z.enum([\n \"string\",\n \"number\",\n \"integer\",\n \"boolean\",\n \"object\",\n \"array\",\n \"null\",\n]);\n\nexport const AddFormSchema = z.object({\n key: z\n .string()\n .trim()\n .min(1, { message: \"Key must be at least 1 character long\" }),\n property: z.object({\n title: z\n .string()\n .trim()\n .min(1, { message: \"Title must be at least 1 character long\" }),\n type: zodJsonTypes.or(z.array(zodJsonTypes)),\n description: z.string().optional(),\n enum: z\n .array(\n z\n .string()\n .or(z.number())\n .or(z.null())\n .or(z.boolean())\n .or(z.record(z.string(), z.any())),\n )\n .optional(),\n items: z\n .object({\n type: zodJsonTypes.or(z.array(zodJsonTypes)),\n })\n //only to satisfy the other types but we actually don't handle it\n .or(\n z.array(\n z\n .object({ type: zodJsonTypes.or(z.array(zodJsonTypes)) })\n .or(z.boolean()),\n ),\n )\n .or(z.boolean())\n .optional(),\n }),\n required: z.boolean().default(false),\n constraints: z\n .array(\n z.custom<Constraint>(() => ({\n name: z.string().trim().min(1),\n value: z.any(),\n })),\n )\n .optional(),\n});\n\n/**\n * Handles adding a property to a parent JSON schema's \"properties\".\n * This means you are working under a child property.\n */\nexport function AddPropertyDialog({\n open,\n onOpenChange,\n onSubmit,\n}: AddPropertyDialogProps) {\n const form = useForm<z.infer<typeof AddFormSchema>>({\n resolver: zodResolver(AddFormSchema),\n defaultValues: {\n key: \"\",\n property: {\n title: \"\",\n },\n },\n });\n\n const currentConstraints = form.watch(\"constraints\");\n const currentProperty = form.watch(\"property\");\n const currentEnum = form.watch(\"property.enum\");\n const currentType = form.watch(\"property.type\");\n\n const {\n getConstraintDefinitionsForType,\n getRendererForConstraint,\n validateConstraintValue,\n } = useConstraints();\n\n const handleSubmit = (data: z.infer<typeof AddFormSchema>) => {\n const { key, property, required, constraints } = data;\n const propertyToSubmit: JSONSchema7 = {\n ...property,\n ...constraints?.reduce((acc, constraint) => {\n return {\n ...acc,\n [constraint.name]: constraint.value,\n } satisfies JSONSchema7;\n }, {}),\n };\n onSubmit(key, propertyToSubmit, required);\n form.reset();\n };\n\n const handleConstraintChange = (\n index: number,\n newVal: Constraint[\"value\"],\n ) => {\n const constraintsCopy = clone(currentConstraints);\n\n const constraintToChange = constraintsCopy?.[index];\n\n if (!constraintToChange) {\n form.setError(`constraints.${index}`, {\n message: \"The constraint was not found\",\n type: \"constraint_not_found\",\n });\n return;\n }\n\n const validationResult = validateConstraintValue(\n constraintToChange.name,\n newVal,\n );\n\n if (validationResult.status === \"error\") {\n let message = validationResult.message;\n if (validationResult.code === \"invalid\") {\n message = `${message}: ${validationResult.error?.map((i) => i.message).join(\", \")}`;\n }\n form.setError(`constraints.${index}`, {\n type: validationResult.code,\n message,\n });\n return;\n }\n\n //edit reference\n constraintToChange.value = newVal;\n form.setValue(\"constraints\", constraintsCopy);\n form.clearErrors(`constraints.${index}`);\n };\n\n const handleRemoveConstraint = (constraintName: Constraint[\"name\"]) => {\n if (!currentConstraints) return;\n const copy = clone(currentConstraints);\n const newConstraints = copy.filter((c) => c.name !== constraintName);\n form.setValue(\"constraints\", newConstraints);\n };\n\n const availableDefinitions = getConstraintDefinitionsForType(\n typeof currentProperty?.type === \"string\" ? currentProperty.type : \"\",\n );\n\n return (\n <Dialog open={open} onOpenChange={onOpenChange}>\n <DialogContent data-testid=\"add-property-dialog\">\n <DialogHeader>\n <DialogTitle>Add</DialogTitle>\n <DialogDescription>\n Required property values and constraints\n </DialogDescription>\n </DialogHeader>\n <Form {...form}>\n <form\n onSubmit={(e) => {\n e.stopPropagation();\n e.preventDefault();\n void form.handleSubmit(handleSubmit)(e);\n }}\n className=\"space-y-4\"\n data-testid=\"add-property-form\"\n id=\"add-property-form\"\n >\n <div className=\"space-y-2\">\n <FormField\n control={form.control}\n name=\"key\"\n render={({ field }) => {\n // Pull the onChange since debounced input should\n // be calling onDebounce instead\n const { onChange, ...rest } = field;\n\n return (\n <FormItem>\n <FormLabel>Property Key</FormLabel>\n <FormControl>\n <DebouncedInput\n {...rest}\n onDebounce={(newVal) => onChange(newVal)}\n />\n </FormControl>\n <FormMessage />\n </FormItem>\n );\n }}\n />\n </div>\n <div className=\"space-y-2\">\n <FormField\n control={form.control}\n name=\"property.title\"\n render={({ field }) => {\n const { onChange, ...rest } = field;\n return (\n <FormItem>\n <FormLabel>Property Title</FormLabel>\n <FormControl>\n <DebouncedInput\n {...rest}\n onDebounce={(newVal) => onChange(newVal)}\n />\n </FormControl>\n <FormMessage />\n </FormItem>\n );\n }}\n />\n </div>\n <div className=\"space-y-2\">\n <FormField\n control={form.control}\n name=\"property.type\"\n render={({ field }) => {\n return (\n <FormItem>\n <FormLabel>Type</FormLabel>\n <FormControl>\n <Select\n value={\n !Array.isArray(field.value)\n ? field.value\n : undefined\n }\n onValueChange={(newVal) => {\n if (newVal === \"enum\") {\n form.setValue(\"property.enum\", []);\n } else {\n form.setValue(\"property.enum\", undefined);\n }\n\n // If changing away from array, clear any array item errors\n if (field.value === \"array\" && newVal !== \"array\") {\n form.clearErrors(\"property.items\");\n form.setValue(\"property.items\", undefined);\n }\n\n field.onChange(newVal);\n }}\n >\n <SelectTrigger\n className=\"w-full\"\n aria-label=\"Select type\"\n >\n <SelectValue />\n </SelectTrigger>\n <SelectContent>\n <SelectItem\n value={\"string\" satisfies JSONSchema7TypeName}\n >\n string\n </SelectItem>\n <SelectItem\n value={\"number\" satisfies JSONSchema7TypeName}\n >\n number\n </SelectItem>\n <SelectItem\n value={\"integer\" satisfies JSONSchema7TypeName}\n >\n integer\n </SelectItem>\n <SelectItem\n value={\"boolean\" satisfies JSONSchema7TypeName}\n >\n boolean\n </SelectItem>\n <SelectItem\n value={\"object\" satisfies JSONSchema7TypeName}\n >\n object\n </SelectItem>\n <SelectItem\n value={\"array\" satisfies JSONSchema7TypeName}\n >\n array\n </SelectItem>\n <SelectItem\n value={\"null\" satisfies JSONSchema7TypeName}\n >\n null\n </SelectItem>\n </SelectContent>\n </Select>\n </FormControl>\n <FormMessage />\n </FormItem>\n );\n }}\n />\n </div>\n\n {/* Array Items Type selector */}\n {currentType === \"array\" && (\n <div className=\"space-y-2\">\n <FormField\n control={form.control}\n name=\"property.items.type\"\n render={({ field }) => {\n return (\n <FormItem>\n <FormLabel>Items of type</FormLabel>\n <FormControl>\n <Select\n value={\n !Array.isArray(field.value)\n ? field.value\n : undefined\n }\n onValueChange={(newVal) => {\n form.clearErrors(\"property.items.type\");\n form.setValue(\n \"property.items.type\",\n newVal as JSONSchema7TypeName,\n );\n }}\n >\n <SelectTrigger\n className=\"w-full\"\n aria-label=\"Select items of type\"\n >\n <SelectValue placeholder=\"Select item type\" />\n </SelectTrigger>\n <SelectContent>\n <SelectItem\n value={\"string\" satisfies JSONSchema7TypeName}\n >\n string\n </SelectItem>\n <SelectItem\n value={\"number\" satisfies JSONSchema7TypeName}\n >\n number\n </SelectItem>\n <SelectItem\n value={\"integer\" satisfies JSONSchema7TypeName}\n >\n integer\n </SelectItem>\n <SelectItem\n value={\"boolean\" satisfies JSONSchema7TypeName}\n >\n boolean\n </SelectItem>\n <SelectItem\n value={\"object\" satisfies JSONSchema7TypeName}\n >\n object\n </SelectItem>\n <SelectItem\n value={\"array\" satisfies JSONSchema7TypeName}\n >\n array\n </SelectItem>\n <SelectItem\n value={\"null\" satisfies JSONSchema7TypeName}\n >\n null\n </SelectItem>\n </SelectContent>\n </Select>\n </FormControl>\n <FormMessage />\n </FormItem>\n );\n }}\n />\n </div>\n )}\n\n <div className=\"flex items-center space-x-2\">\n <FormField\n control={form.control}\n name=\"required\"\n render={({ field }) => {\n return (\n <FormItem>\n <FormControl>\n <Switch\n checked={field.value}\n onCheckedChange={(checked) => field.onChange(checked)}\n />\n </FormControl>\n <FormLabel>Required</FormLabel>\n <FormMessage />\n </FormItem>\n );\n }}\n />\n </div>\n <div className=\"space-y-2\">\n <FormField\n control={form.control}\n name=\"property.description\"\n render={({ field }) => {\n return (\n <FormItem>\n <FormLabel>Description</FormLabel>\n <FormControl>\n <Input {...field} />\n </FormControl>\n <FormMessage />\n </FormItem>\n );\n }}\n />\n </div>\n {currentEnum ? (\n <FormField\n control={form.control}\n name=\"property.enum\"\n render={({ field }) => {\n return (\n <FormItem>\n <FormLabel>Enum</FormLabel>\n <FormControl>\n <MultiInput\n values={\n field.value?.filter((i) => typeof i === \"string\") ??\n []\n }\n onAddValue={(newVal) => {\n const updates = [];\n if (field.value) {\n updates.push(...field.value);\n }\n updates.push(newVal);\n field.onChange(updates);\n }}\n onRemoveValue={(index) => {\n const newEnums = clone(field.value ?? []);\n newEnums.splice(index, 1);\n field.onChange(newEnums);\n }}\n />\n </FormControl>\n <FormMessage />\n </FormItem>\n );\n }}\n />\n ) : null}\n\n {availableDefinitions.length ? (\n <div className=\"space-y-2\">\n <Label>Constraints</Label>\n <ConstraintsAdd\n addedConstraints={currentConstraints ?? []}\n availableDefinitions={availableDefinitions}\n onAdd={(newConstraints) => {\n form.setValue(\"constraints\", newConstraints);\n }}\n />\n <Separator />\n {currentConstraints?.map((constraint, i) => {\n const Renderer = getRendererForConstraint(constraint.name);\n if (!Renderer) return null;\n\n const error = form.formState.errors.constraints?.[i];\n let mappedError: OperationError | undefined;\n\n if (error) {\n mappedError = {\n code: error?.type ?? \"INVALID\",\n message: error.message ?? \"An error occurred\",\n };\n }\n\n return (\n <Renderer\n key={constraint.name}\n constraintName={constraint.name}\n value={constraint.value}\n onConstraintChange={(newVal) => {\n handleConstraintChange(i, newVal);\n }}\n onRemoveConstraint={() => {\n handleRemoveConstraint(constraint.name);\n }}\n error={mappedError}\n />\n );\n })}\n </div>\n ) : null}\n\n <DialogFooter>\n <Button type=\"submit\" form=\"add-property-form\">\n Add Property\n </Button>\n </DialogFooter>\n </form>\n </Form>\n </DialogContent>\n </Dialog>\n );\n}\n"],"names":["zodJsonTypes","z","AddFormSchema","AddPropertyDialog","open","onOpenChange","onSubmit","form","useForm","zodResolver","currentConstraints","currentProperty","currentEnum","currentType","getConstraintDefinitionsForType","getRendererForConstraint","validateConstraintValue","useConstraints","handleSubmit","data","key","property","required","constraints","propertyToSubmit","acc","constraint","handleConstraintChange","index","newVal","constraintsCopy","clone","constraintToChange","validationResult","message","i","handleRemoveConstraint","constraintName","newConstraints","availableDefinitions","Dialog","jsxs","DialogContent","DialogHeader","jsx","DialogTitle","DialogDescription","Form","e","FormField","field","onChange","rest","FormItem","FormLabel","FormControl","DebouncedInput","FormMessage","Select","SelectTrigger","SelectValue","SelectContent","SelectItem","Switch","checked","Input","MultiInput","updates","newEnums","Label","ConstraintsAdd","Separator","Renderer","error","mappedError","DialogFooter","Button"],"mappings":"skBA8CMA,EAAeC,IAAE,KAAK,CAC1B,SACA,SACA,UACA,UACA,SACA,QACA,MACF,CAAC,EAEYC,EAAgBD,IAAE,OAAO,CACpC,IAAKA,EAAAA,EACF,OAAA,EACA,KAAA,EACA,IAAI,EAAG,CAAE,QAAS,wCAAyC,EAC9D,SAAUA,IAAE,OAAO,CACjB,MAAOA,EAAAA,EACJ,OAAA,EACA,KAAA,EACA,IAAI,EAAG,CAAE,QAAS,0CAA2C,EAChE,KAAMD,EAAa,GAAGC,EAAE,EAAA,MAAMD,CAAY,CAAC,EAC3C,YAAaC,EAAA,EAAE,OAAO,EAAE,SAAS,EACjC,KAAMA,EACH,EAAA,MACCA,EAAAA,EACG,OAAO,EACP,GAAGA,IA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|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),u=require("./index.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),u=require("./index.cjs63.js"),i=require("react/jsx-runtime");function c(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const e in t)if(e!=="default"){const a=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(r,e,a.get?a:{enumerable:!0,get:()=>t[e]})}}return r.default=t,Object.freeze(r)}const l=c(n);var s="Label",o=l.forwardRef((t,r)=>i.jsx(u.Primitive.label,{...t,ref:r,onMouseDown:e=>{e.target.closest("button, input, select, textarea")||(t.onMouseDown?.(e),!e.defaultPrevented&&e.detail>1&&e.preventDefault())}}));o.displayName=s;var f=o;exports.Label=o;exports.Root=f;
|
|
2
2
|
//# sourceMappingURL=index.cjs31.js.map
|
package/dist/index.cjs34.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react"),m=require("./index.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("react"),m=require("./index.cjs58.js"),a=require("react/jsx-runtime");function y(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const o=y(g);var p=o.forwardRef((e,t)=>{const{children:r,...n}=e,l=o.Children.toArray(r),i=l.find(b);if(i){const s=i.props.children,c=l.map(f=>f===i?o.Children.count(s)>1?o.Children.only(null):o.isValidElement(s)?s.props.children:null:f);return a.jsx(u,{...n,ref:t,children:o.isValidElement(s)?o.cloneElement(s,void 0,c):null})}return a.jsx(u,{...n,ref:t,children:r})});p.displayName="Slot";var u=o.forwardRef((e,t)=>{const{children:r,...n}=e;if(o.isValidElement(r)){const l=S(r),i=j(n,r.props);return r.type!==o.Fragment&&(i.ref=t?m.composeRefs(t,l):l),o.cloneElement(r,i)}return o.Children.count(r)>1?o.Children.only(null):null});u.displayName="SlotClone";var d=({children:e})=>a.jsx(a.Fragment,{children:e});function b(e){return o.isValidElement(e)&&e.type===d}function j(e,t){const r={...t};for(const n in t){const l=e[n],i=t[n];/^on[A-Z]/.test(n)?l&&i?r[n]=(...c)=>{i(...c),l(...c)}:l&&(r[n]=l):n==="style"?r[n]={...l,...i}:n==="className"&&(r[n]=[l,i].filter(Boolean).join(" "))}return{...e,...r}}function S(e){let t=Object.getOwnPropertyDescriptor(e.props,"ref")?.get,r=t&&"isReactWarning"in t&&t.isReactWarning;return r?e.ref:(t=Object.getOwnPropertyDescriptor(e,"ref")?.get,r=t&&"isReactWarning"in t&&t.isReactWarning,r?e.props.ref:e.props.ref||e.ref)}exports.Slot=p;exports.Slottable=d;
|
|
2
2
|
//# sourceMappingURL=index.cjs34.js.map
|
package/dist/index.cjs36.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("react"),_=require("./index.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("react"),_=require("./index.cjs57.js"),E=require("./index.cjs58.js"),O=require("./index.cjs59.js"),M=require("./index.cjs60.js"),$=require("./index.cjs61.js"),N=require("./index.cjs62.js"),C=require("./index.cjs63.js"),d=require("react/jsx-runtime");function H(e){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(o,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return o.default=e,Object.freeze(o)}const s=H(T);var v="Switch",[I,z]=O.createContextScope(v),[B,D]=I(v),w=s.forwardRef((e,o)=>{const{__scopeSwitch:t,name:r,checked:c,defaultChecked:l,required:i,disabled:n,value:a="on",onCheckedChange:b,form:S,...p}=e,[u,y]=s.useState(null),j=E.useComposedRefs(o,f=>y(f)),m=s.useRef(!1),x=u?S||!!u.closest("form"):!0,[h=!1,R]=M.useControllableState({prop:c,defaultProp:l,onChange:b});return d.jsxs(B,{scope:t,checked:h,disabled:n,children:[d.jsx(C.Primitive.button,{type:"button",role:"switch","aria-checked":h,"aria-required":i,"data-state":g(h),"data-disabled":n?"":void 0,disabled:n,value:a,...p,ref:j,onClick:_.composeEventHandlers(e.onClick,f=>{R(q=>!q),x&&(m.current=f.isPropagationStopped(),m.current||f.stopPropagation())})}),x&&d.jsx(A,{control:u,bubbles:!m.current,name:r,value:a,checked:h,required:i,disabled:n,form:S,style:{transform:"translateX(-100%)"}})]})});w.displayName=v;var P="SwitchThumb",k=s.forwardRef((e,o)=>{const{__scopeSwitch:t,...r}=e,c=D(P,t);return d.jsx(C.Primitive.span,{"data-state":g(c.checked),"data-disabled":c.disabled?"":void 0,...r,ref:o})});k.displayName=P;var A=e=>{const{control:o,checked:t,bubbles:r=!0,...c}=e,l=s.useRef(null),i=$.usePrevious(t),n=N.useSize(o);return s.useEffect(()=>{const a=l.current,b=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(b,"checked").set;if(i!==t&&p){const u=new Event("click",{bubbles:r});p.call(a,t),a.dispatchEvent(u)}},[i,t,r]),d.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:t,...c,tabIndex:-1,ref:l,style:{...e.style,...n,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})};function g(e){return e?"checked":"unchecked"}var F=w,L=k;exports.Root=F;exports.Switch=w;exports.SwitchThumb=k;exports.Thumb=L;exports.createSwitchScope=z;
|
|
2
2
|
//# sourceMappingURL=index.cjs36.js.map
|
package/dist/index.cjs37.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const st=require("react"),ct=require("react-dom"),Le=require("./index.cjs62.js"),E=require("./index.cjs56.js"),lt=require("./index.cjs63.js"),H=require("./index.cjs57.js"),it=require("./index.cjs58.js"),at=require("./index.cjs64.js"),dt=require("./index.cjs65.js"),ut=require("./index.cjs66.js"),pt=require("./index.cjs67.js"),Ie=require("./index.cjs68.js"),ee=require("./index.cjs69.js"),ft=require("./index.cjs70.js"),M=require("./index.cjs55.js"),mt=require("./index.cjs34.js"),ht=require("./index.cjs71.js"),ke=require("./index.cjs59.js"),$=require("./index.cjs72.js"),vt=require("./index.cjs60.js"),St=require("./index.cjs73.js"),gt=require("./index.cjs74.js"),xt=require("./index.cjs75.js"),d=require("react/jsx-runtime");function Ve(o){const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const e in o)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(o,e);Object.defineProperty(l,e,i.get?i:{enumerable:!0,get:()=>o[e]})}}return l.default=o,Object.freeze(l)}const t=Ve(st),Be=Ve(ct);var wt=[" ","Enter","ArrowUp","ArrowDown"],Ct=[" ","Enter"],se="Select",[ae,de,yt]=lt.createCollection(se),[te,It]=it.createContextScope(se,[yt,ee.createPopperScope]),ue=ee.createPopperScope(),[Tt,G]=te(se),[Pt,Et]=te(se),Te=o=>{const{__scopeSelect:l,children:e,open:i,defaultOpen:r,onOpenChange:u,value:n,defaultValue:s,onValueChange:c,dir:f,name:S,autoComplete:w,disabled:R,required:T,form:y}=o,a=ue(l),[h,g]=t.useState(null),[m,v]=t.useState(null),[F,O]=t.useState(!1),oe=at.useDirection(f),[b=!1,D]=ke.useControllableState({prop:i,defaultProp:r,onChange:u}),[W,Y]=ke.useControllableState({prop:n,defaultProp:s,onChange:c}),L=t.useRef(null),k=h?y||!!h.closest("form"):!0,[U,V]=t.useState(new Set),B=Array.from(U).map(_=>_.props.value).join(";");return d.jsx(ee.Root,{...a,children:d.jsxs(Tt,{required:T,scope:l,trigger:h,onTriggerChange:g,valueNode:m,onValueNodeChange:v,valueNodeHasChildren:F,onValueNodeHasChildrenChange:O,contentId:Ie.useId(),value:W,onValueChange:Y,open:b,onOpenChange:D,dir:oe,triggerPointerDownPosRef:L,disabled:R,children:[d.jsx(ae.Provider,{scope:l,children:d.jsx(Pt,{scope:o.__scopeSelect,onNativeOptionAdd:t.useCallback(_=>{V(j=>new Set(j).add(_))},[]),onNativeOptionRemove:t.useCallback(_=>{V(j=>{const q=new Set(j);return q.delete(_),q})},[]),children:e})}),k?d.jsxs(ot,{"aria-hidden":!0,required:T,tabIndex:-1,name:S,autoComplete:w,value:W,onChange:_=>Y(_.target.value),disabled:R,form:y,children:[W===void 0?d.jsx("option",{value:""}):null,Array.from(U)]},B):null]})})};Te.displayName=se;var qe="SelectTrigger",Pe=t.forwardRef((o,l)=>{const{__scopeSelect:e,disabled:i=!1,...r}=o,u=ue(e),n=G(qe,e),s=n.disabled||i,c=H.useComposedRefs(l,n.onTriggerChange),f=de(e),S=t.useRef("touch"),[w,R,T]=nt(a=>{const h=f().filter(v=>!v.disabled),g=h.find(v=>v.value===n.value),m=rt(h,a,g);m!==void 0&&n.onValueChange(m.value)}),y=a=>{s||(n.onOpenChange(!0),T()),a&&(n.triggerPointerDownPosRef.current={x:Math.round(a.pageX),y:Math.round(a.pageY)})};return d.jsx(ee.Anchor,{asChild:!0,...u,children:d.jsx(M.Primitive.button,{type:"button",role:"combobox","aria-controls":n.contentId,"aria-expanded":n.open,"aria-required":n.required,"aria-autocomplete":"none",dir:n.dir,"data-state":n.open?"open":"closed",disabled:s,"data-disabled":s?"":void 0,"data-placeholder":tt(n.value)?"":void 0,...r,ref:c,onClick:E.composeEventHandlers(r.onClick,a=>{a.currentTarget.focus(),S.current!=="mouse"&&y(a)}),onPointerDown:E.composeEventHandlers(r.onPointerDown,a=>{S.current=a.pointerType;const h=a.target;h.hasPointerCapture(a.pointerId)&&h.releasePointerCapture(a.pointerId),a.button===0&&a.ctrlKey===!1&&a.pointerType==="mouse"&&(y(a),a.preventDefault())}),onKeyDown:E.composeEventHandlers(r.onKeyDown,a=>{const h=w.current!=="";!(a.ctrlKey||a.altKey||a.metaKey)&&a.key.length===1&&R(a.key),!(h&&a.key===" ")&&wt.includes(a.key)&&(y(),a.preventDefault())})})})});Pe.displayName=qe;var Fe="SelectValue",Ee=t.forwardRef((o,l)=>{const{__scopeSelect:e,className:i,style:r,children:u,placeholder:n="",...s}=o,c=G(Fe,e),{onValueNodeHasChildrenChange:f}=c,S=u!==void 0,w=H.useComposedRefs(l,c.onValueNodeChange);return $.useLayoutEffect(()=>{f(S)},[f,S]),d.jsx(M.Primitive.span,{...s,ref:w,style:{pointerEvents:"none"},children:tt(c.value)?d.jsx(d.Fragment,{children:n}):u})});Ee.displayName=Fe;var Rt="SelectIcon",Re=t.forwardRef((o,l)=>{const{__scopeSelect:e,children:i,...r}=o;return d.jsx(M.Primitive.span,{"aria-hidden":!0,...r,ref:l,children:i||"▼"})});Re.displayName=Rt;var bt="SelectPortal",be=o=>d.jsx(ft.Portal,{asChild:!0,...o});be.displayName=bt;var J="SelectContent",_e=t.forwardRef((o,l)=>{const e=G(J,o.__scopeSelect),[i,r]=t.useState();if($.useLayoutEffect(()=>{r(new DocumentFragment)},[]),!e.open){const u=i;return u?Be.createPortal(d.jsx(We,{scope:o.__scopeSelect,children:d.jsx(ae.Slot,{scope:o.__scopeSelect,children:d.jsx("div",{children:o.children})})}),u):null}return d.jsx(Ue,{...o,ref:l})});_e.displayName=J;var A=10,[We,z]=te(J),_t="SelectContentImpl",Ue=t.forwardRef((o,l)=>{const{__scopeSelect:e,position:i="item-aligned",onCloseAutoFocus:r,onEscapeKeyDown:u,onPointerDownOutside:n,side:s,sideOffset:c,align:f,alignOffset:S,arrowPadding:w,collisionBoundary:R,collisionPadding:T,sticky:y,hideWhenDetached:a,avoidCollisions:h,...g}=o,m=G(J,e),[v,F]=t.useState(null),[O,oe]=t.useState(null),b=H.useComposedRefs(l,p=>F(p)),[D,W]=t.useState(null),[Y,L]=t.useState(null),k=de(e),[U,V]=t.useState(!1),B=t.useRef(!1);t.useEffect(()=>{if(v)return gt.hideOthers(v)},[v]),ut.useFocusGuards();const _=t.useCallback(p=>{const[I,...N]=k().map(P=>P.ref.current),[x]=N.slice(-1),C=document.activeElement;for(const P of p)if(P===C||(P?.scrollIntoView({block:"nearest"}),P===I&&O&&(O.scrollTop=0),P===x&&O&&(O.scrollTop=O.scrollHeight),P?.focus(),document.activeElement!==C))return},[k,O]),j=t.useCallback(()=>_([D,v]),[_,D,v]);t.useEffect(()=>{U&&j()},[U,j]);const{onOpenChange:q,triggerPointerDownPosRef:K}=m;t.useEffect(()=>{if(v){let p={x:0,y:0};const I=x=>{p={x:Math.abs(Math.round(x.pageX)-(K.current?.x??0)),y:Math.abs(Math.round(x.pageY)-(K.current?.y??0))}},N=x=>{p.x<=10&&p.y<=10?x.preventDefault():v.contains(x.target)||q(!1),document.removeEventListener("pointermove",I),K.current=null};return K.current!==null&&(document.addEventListener("pointermove",I),document.addEventListener("pointerup",N,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",I),document.removeEventListener("pointerup",N,{capture:!0})}}},[v,q,K]),t.useEffect(()=>{const p=()=>q(!1);return window.addEventListener("blur",p),window.addEventListener("resize",p),()=>{window.removeEventListener("blur",p),window.removeEventListener("resize",p)}},[q]);const[pe,ce]=nt(p=>{const I=k().filter(C=>!C.disabled),N=I.find(C=>C.ref.current===document.activeElement),x=rt(I,p,N);x&&setTimeout(()=>x.ref.current.focus())}),fe=t.useCallback((p,I,N)=>{const x=!B.current&&!N;(m.value!==void 0&&m.value===I||x)&&(W(p),x&&(B.current=!0))},[m.value]),me=t.useCallback(()=>v?.focus(),[v]),Q=t.useCallback((p,I,N)=>{const x=!B.current&&!N;(m.value!==void 0&&m.value===I||x)&&L(p)},[m.value]),le=i==="popper"?ge:Ke,ne=le===ge?{side:s,sideOffset:c,align:f,alignOffset:S,arrowPadding:w,collisionBoundary:R,collisionPadding:T,sticky:y,hideWhenDetached:a,avoidCollisions:h}:{};return d.jsx(We,{scope:e,content:v,viewport:O,onViewportChange:oe,itemRefCallback:fe,selectedItem:D,onItemLeave:me,itemTextRefCallback:Q,focusSelectedItem:j,selectedItemText:Y,position:i,isPositioned:U,searchRef:pe,children:d.jsx(xt.default,{as:mt.Slot,allowPinchZoom:!0,children:d.jsx(pt.FocusScope,{asChild:!0,trapped:m.open,onMountAutoFocus:p=>{p.preventDefault()},onUnmountAutoFocus:E.composeEventHandlers(r,p=>{m.trigger?.focus({preventScroll:!0}),p.preventDefault()}),children:d.jsx(dt.DismissableLayer,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:u,onPointerDownOutside:n,onFocusOutside:p=>p.preventDefault(),onDismiss:()=>m.onOpenChange(!1),children:d.jsx(le,{role:"listbox",id:m.contentId,"data-state":m.open?"open":"closed",dir:m.dir,onContextMenu:p=>p.preventDefault(),...g,...ne,onPlaced:()=>V(!0),ref:b,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:E.composeEventHandlers(g.onKeyDown,p=>{const I=p.ctrlKey||p.altKey||p.metaKey;if(p.key==="Tab"&&p.preventDefault(),!I&&p.key.length===1&&ce(p.key),["ArrowUp","ArrowDown","Home","End"].includes(p.key)){let x=k().filter(C=>!C.disabled).map(C=>C.ref.current);if(["ArrowUp","End"].includes(p.key)&&(x=x.slice().reverse()),["ArrowUp","ArrowDown"].includes(p.key)){const C=p.target,P=x.indexOf(C);x=x.slice(P+1)}setTimeout(()=>_(x)),p.preventDefault()}})})})})})})});Ue.displayName=_t;var Nt="SelectItemAlignedPosition",Ke=t.forwardRef((o,l)=>{const{__scopeSelect:e,onPlaced:i,...r}=o,u=G(J,e),n=z(J,e),[s,c]=t.useState(null),[f,S]=t.useState(null),w=H.useComposedRefs(l,b=>S(b)),R=de(e),T=t.useRef(!1),y=t.useRef(!0),{viewport:a,selectedItem:h,selectedItemText:g,focusSelectedItem:m}=n,v=t.useCallback(()=>{if(u.trigger&&u.valueNode&&s&&f&&a&&h&&g){const b=u.trigger.getBoundingClientRect(),D=f.getBoundingClientRect(),W=u.valueNode.getBoundingClientRect(),Y=g.getBoundingClientRect();if(u.dir!=="rtl"){const C=Y.left-D.left,P=W.left-C,X=b.left-P,Z=b.width+X,he=Math.max(Z,D.width),ve=window.innerWidth-A,Se=Le.clamp(P,[A,Math.max(A,ve-he)]);s.style.minWidth=Z+"px",s.style.left=Se+"px"}else{const C=D.right-Y.right,P=window.innerWidth-W.right-C,X=window.innerWidth-b.right-P,Z=b.width+X,he=Math.max(Z,D.width),ve=window.innerWidth-A,Se=Le.clamp(P,[A,Math.max(A,ve-he)]);s.style.minWidth=Z+"px",s.style.right=Se+"px"}const L=R(),k=window.innerHeight-A*2,U=a.scrollHeight,V=window.getComputedStyle(f),B=parseInt(V.borderTopWidth,10),_=parseInt(V.paddingTop,10),j=parseInt(V.borderBottomWidth,10),q=parseInt(V.paddingBottom,10),K=B+_+U+q+j,pe=Math.min(h.offsetHeight*5,K),ce=window.getComputedStyle(a),fe=parseInt(ce.paddingTop,10),me=parseInt(ce.paddingBottom,10),Q=b.top+b.height/2-A,le=k-Q,ne=h.offsetHeight/2,p=h.offsetTop+ne,I=B+_+p,N=K-I;if(I<=Q){const C=L.length>0&&h===L[L.length-1].ref.current;s.style.bottom="0px";const P=f.clientHeight-a.offsetTop-a.offsetHeight,X=Math.max(le,ne+(C?me:0)+P+j),Z=I+X;s.style.height=Z+"px"}else{const C=L.length>0&&h===L[0].ref.current;s.style.top="0px";const X=Math.max(Q,B+a.offsetTop+(C?fe:0)+ne)+N;s.style.height=X+"px",a.scrollTop=I-Q+a.offsetTop}s.style.margin=`${A}px 0`,s.style.minHeight=pe+"px",s.style.maxHeight=k+"px",i?.(),requestAnimationFrame(()=>T.current=!0)}},[R,u.trigger,u.valueNode,s,f,a,h,g,u.dir,i]);$.useLayoutEffect(()=>v(),[v]);const[F,O]=t.useState();$.useLayoutEffect(()=>{f&&O(window.getComputedStyle(f).zIndex)},[f]);const oe=t.useCallback(b=>{b&&y.current===!0&&(v(),m?.(),y.current=!1)},[v,m]);return d.jsx(Ot,{scope:e,contentWrapper:s,shouldExpandOnScrollRef:T,onScrollButtonChange:oe,children:d.jsx("div",{ref:c,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:F},children:d.jsx(M.Primitive.div,{...r,ref:w,style:{boxSizing:"border-box",maxHeight:"100%",...r.style}})})})});Ke.displayName=Nt;var Mt="SelectPopperPosition",ge=t.forwardRef((o,l)=>{const{__scopeSelect:e,align:i="start",collisionPadding:r=A,...u}=o,n=ue(e);return d.jsx(ee.Content,{...n,...u,ref:l,align:i,collisionPadding:r,style:{boxSizing:"border-box",...u.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});ge.displayName=Mt;var[Ot,Ne]=te(J,{}),xe="SelectViewport",Me=t.forwardRef((o,l)=>{const{__scopeSelect:e,nonce:i,...r}=o,u=z(xe,e),n=Ne(xe,e),s=H.useComposedRefs(l,u.onViewportChange),c=t.useRef(0);return d.jsxs(d.Fragment,{children:[d.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:i}),d.jsx(ae.Slot,{scope:e,children:d.jsx(M.Primitive.div,{"data-radix-select-viewport":"",role:"presentation",...r,ref:s,style:{position:"relative",flex:1,overflow:"hidden auto",...r.style},onScroll:E.composeEventHandlers(r.onScroll,f=>{const S=f.currentTarget,{contentWrapper:w,shouldExpandOnScrollRef:R}=n;if(R?.current&&w){const T=Math.abs(c.current-S.scrollTop);if(T>0){const y=window.innerHeight-A*2,a=parseFloat(w.style.minHeight),h=parseFloat(w.style.height),g=Math.max(a,h);if(g<y){const m=g+T,v=Math.min(y,m),F=m-v;w.style.height=v+"px",w.style.bottom==="0px"&&(S.scrollTop=F>0?F:0,w.style.justifyContent="flex-end")}}}c.current=S.scrollTop})})})]})});Me.displayName=xe;var $e="SelectGroup",[At,Dt]=te($e),Ge=t.forwardRef((o,l)=>{const{__scopeSelect:e,...i}=o,r=Ie.useId();return d.jsx(At,{scope:e,id:r,children:d.jsx(M.Primitive.div,{role:"group","aria-labelledby":r,...i,ref:l})})});Ge.displayName=$e;var ze="SelectLabel",Ye=t.forwardRef((o,l)=>{const{__scopeSelect:e,...i}=o,r=Dt(ze,e);return d.jsx(M.Primitive.div,{id:r.id,...i,ref:l})});Ye.displayName=ze;var ie="SelectItem",[jt,Xe]=te(ie),Oe=t.forwardRef((o,l)=>{const{__scopeSelect:e,value:i,disabled:r=!1,textValue:u,...n}=o,s=G(ie,e),c=z(ie,e),f=s.value===i,[S,w]=t.useState(u??""),[R,T]=t.useState(!1),y=H.useComposedRefs(l,m=>c.itemRefCallback?.(m,i,r)),a=Ie.useId(),h=t.useRef("touch"),g=()=>{r||(s.onValueChange(i),s.onOpenChange(!1))};if(i==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return d.jsx(jt,{scope:e,value:i,disabled:r,textId:a,isSelected:f,onItemTextChange:t.useCallback(m=>{w(v=>v||(m?.textContent??"").trim())},[]),children:d.jsx(ae.ItemSlot,{scope:e,value:i,disabled:r,textValue:S,children:d.jsx(M.Primitive.div,{role:"option","aria-labelledby":a,"data-highlighted":R?"":void 0,"aria-selected":f&&R,"data-state":f?"checked":"unchecked","aria-disabled":r||void 0,"data-disabled":r?"":void 0,tabIndex:r?void 0:-1,...n,ref:y,onFocus:E.composeEventHandlers(n.onFocus,()=>T(!0)),onBlur:E.composeEventHandlers(n.onBlur,()=>T(!1)),onClick:E.composeEventHandlers(n.onClick,()=>{h.current!=="mouse"&&g()}),onPointerUp:E.composeEventHandlers(n.onPointerUp,()=>{h.current==="mouse"&&g()}),onPointerDown:E.composeEventHandlers(n.onPointerDown,m=>{h.current=m.pointerType}),onPointerMove:E.composeEventHandlers(n.onPointerMove,m=>{h.current=m.pointerType,r?c.onItemLeave?.():h.current==="mouse"&&m.currentTarget.focus({preventScroll:!0})}),onPointerLeave:E.composeEventHandlers(n.onPointerLeave,m=>{m.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:E.composeEventHandlers(n.onKeyDown,m=>{c.searchRef?.current!==""&&m.key===" "||(Ct.includes(m.key)&&g(),m.key===" "&&m.preventDefault())})})})})});Oe.displayName=ie;var re="SelectItemText",Ae=t.forwardRef((o,l)=>{const{__scopeSelect:e,className:i,style:r,...u}=o,n=G(re,e),s=z(re,e),c=Xe(re,e),f=Et(re,e),[S,w]=t.useState(null),R=H.useComposedRefs(l,g=>w(g),c.onItemTextChange,g=>s.itemTextRefCallback?.(g,c.value,c.disabled)),T=S?.textContent,y=t.useMemo(()=>d.jsx("option",{value:c.value,disabled:c.disabled,children:T},c.value),[c.disabled,c.value,T]),{onNativeOptionAdd:a,onNativeOptionRemove:h}=f;return $.useLayoutEffect(()=>(a(y),()=>h(y)),[a,h,y]),d.jsxs(d.Fragment,{children:[d.jsx(M.Primitive.span,{id:c.textId,...u,ref:R}),c.isSelected&&n.valueNode&&!n.valueNodeHasChildren?Be.createPortal(u.children,n.valueNode):null]})});Ae.displayName=re;var Ze="SelectItemIndicator",De=t.forwardRef((o,l)=>{const{__scopeSelect:e,...i}=o;return Xe(Ze,e).isSelected?d.jsx(M.Primitive.span,{"aria-hidden":!0,...i,ref:l}):null});De.displayName=Ze;var we="SelectScrollUpButton",je=t.forwardRef((o,l)=>{const e=z(we,o.__scopeSelect),i=Ne(we,o.__scopeSelect),[r,u]=t.useState(!1),n=H.useComposedRefs(l,i.onScrollButtonChange);return $.useLayoutEffect(()=>{if(e.viewport&&e.isPositioned){let s=function(){const f=c.scrollTop>0;u(f)};const c=e.viewport;return s(),c.addEventListener("scroll",s),()=>c.removeEventListener("scroll",s)}},[e.viewport,e.isPositioned]),r?d.jsx(Je,{...o,ref:n,onAutoScroll:()=>{const{viewport:s,selectedItem:c}=e;s&&c&&(s.scrollTop=s.scrollTop-c.offsetHeight)}}):null});je.displayName=we;var Ce="SelectScrollDownButton",He=t.forwardRef((o,l)=>{const e=z(Ce,o.__scopeSelect),i=Ne(Ce,o.__scopeSelect),[r,u]=t.useState(!1),n=H.useComposedRefs(l,i.onScrollButtonChange);return $.useLayoutEffect(()=>{if(e.viewport&&e.isPositioned){let s=function(){const f=c.scrollHeight-c.clientHeight,S=Math.ceil(c.scrollTop)<f;u(S)};const c=e.viewport;return s(),c.addEventListener("scroll",s),()=>c.removeEventListener("scroll",s)}},[e.viewport,e.isPositioned]),r?d.jsx(Je,{...o,ref:n,onAutoScroll:()=>{const{viewport:s,selectedItem:c}=e;s&&c&&(s.scrollTop=s.scrollTop+c.offsetHeight)}}):null});He.displayName=Ce;var Je=t.forwardRef((o,l)=>{const{__scopeSelect:e,onAutoScroll:i,...r}=o,u=z("SelectScrollButton",e),n=t.useRef(null),s=de(e),c=t.useCallback(()=>{n.current!==null&&(window.clearInterval(n.current),n.current=null)},[]);return t.useEffect(()=>()=>c(),[c]),$.useLayoutEffect(()=>{s().find(S=>S.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:"nearest"})},[s]),d.jsx(M.Primitive.div,{"aria-hidden":!0,...r,ref:l,style:{flexShrink:0,...r.style},onPointerDown:E.composeEventHandlers(r.onPointerDown,()=>{n.current===null&&(n.current=window.setInterval(i,50))}),onPointerMove:E.composeEventHandlers(r.onPointerMove,()=>{u.onItemLeave?.(),n.current===null&&(n.current=window.setInterval(i,50))}),onPointerLeave:E.composeEventHandlers(r.onPointerLeave,()=>{c()})})}),Ht="SelectSeparator",Qe=t.forwardRef((o,l)=>{const{__scopeSelect:e,...i}=o;return d.jsx(M.Primitive.div,{"aria-hidden":!0,...i,ref:l})});Qe.displayName=Ht;var ye="SelectArrow",et=t.forwardRef((o,l)=>{const{__scopeSelect:e,...i}=o,r=ue(e),u=G(ye,e),n=z(ye,e);return u.open&&n.position==="popper"?d.jsx(ee.Arrow,{...r,...i,ref:l}):null});et.displayName=ye;function tt(o){return o===""||o===void 0}var ot=t.forwardRef((o,l)=>{const{value:e,...i}=o,r=t.useRef(null),u=H.useComposedRefs(l,r),n=vt.usePrevious(e);return t.useEffect(()=>{const s=r.current,c=window.HTMLSelectElement.prototype,S=Object.getOwnPropertyDescriptor(c,"value").set;if(n!==e&&S){const w=new Event("change",{bubbles:!0});S.call(s,e),s.dispatchEvent(w)}},[n,e]),d.jsx(St.VisuallyHidden,{asChild:!0,children:d.jsx("select",{...i,ref:u,defaultValue:e})})});ot.displayName="BubbleSelect";function nt(o){const l=ht.useCallbackRef(o),e=t.useRef(""),i=t.useRef(0),r=t.useCallback(n=>{const s=e.current+n;l(s),function c(f){e.current=f,window.clearTimeout(i.current),f!==""&&(i.current=window.setTimeout(()=>c(""),1e3))}(s)},[l]),u=t.useCallback(()=>{e.current="",window.clearTimeout(i.current)},[]);return t.useEffect(()=>()=>window.clearTimeout(i.current),[]),[e,r,u]}function rt(o,l,e){const r=l.length>1&&Array.from(l).every(f=>f===l[0])?l[0]:l,u=e?o.indexOf(e):-1;let n=Lt(o,Math.max(u,0));r.length===1&&(n=n.filter(f=>f!==e));const c=n.find(f=>f.textValue.toLowerCase().startsWith(r.toLowerCase()));return c!==e?c:void 0}function Lt(o,l){return o.map((e,i)=>o[(l+i)%o.length])}var kt=Te,Vt=Pe,Bt=Ee,qt=Re,Ft=be,Wt=_e,Ut=Me,Kt=Oe,$t=Ae,Gt=De,zt=je,Yt=He;exports.Content=Wt;exports.Icon=qt;exports.Item=Kt;exports.ItemIndicator=Gt;exports.ItemText=$t;exports.Portal=Ft;exports.Root=kt;exports.ScrollDownButton=Yt;exports.ScrollUpButton=zt;exports.Select=Te;exports.SelectArrow=et;exports.SelectContent=_e;exports.SelectGroup=Ge;exports.SelectIcon=Re;exports.SelectItem=Oe;exports.SelectItemIndicator=De;exports.SelectItemText=Ae;exports.SelectLabel=Ye;exports.SelectPortal=be;exports.SelectScrollDownButton=He;exports.SelectScrollUpButton=je;exports.SelectSeparator=Qe;exports.SelectTrigger=Pe;exports.SelectValue=Ee;exports.SelectViewport=Me;exports.Trigger=Vt;exports.Value=Bt;exports.Viewport=Ut;exports.createSelectScope=It;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const st=require("react"),ct=require("react-dom"),Le=require("./index.cjs64.js"),E=require("./index.cjs57.js"),lt=require("./index.cjs65.js"),H=require("./index.cjs58.js"),it=require("./index.cjs59.js"),at=require("./index.cjs66.js"),dt=require("./index.cjs67.js"),ut=require("./index.cjs68.js"),pt=require("./index.cjs69.js"),Ie=require("./index.cjs70.js"),ee=require("./index.cjs71.js"),ft=require("./index.cjs72.js"),M=require("./index.cjs63.js"),mt=require("./index.cjs34.js"),ht=require("./index.cjs73.js"),ke=require("./index.cjs60.js"),$=require("./index.cjs74.js"),vt=require("./index.cjs61.js"),St=require("./index.cjs75.js"),gt=require("./index.cjs76.js"),xt=require("./index.cjs77.js"),d=require("react/jsx-runtime");function Ve(o){const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const e in o)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(o,e);Object.defineProperty(l,e,i.get?i:{enumerable:!0,get:()=>o[e]})}}return l.default=o,Object.freeze(l)}const t=Ve(st),Be=Ve(ct);var wt=[" ","Enter","ArrowUp","ArrowDown"],Ct=[" ","Enter"],se="Select",[ae,de,yt]=lt.createCollection(se),[te,It]=it.createContextScope(se,[yt,ee.createPopperScope]),ue=ee.createPopperScope(),[Tt,G]=te(se),[Pt,Et]=te(se),Te=o=>{const{__scopeSelect:l,children:e,open:i,defaultOpen:r,onOpenChange:u,value:n,defaultValue:s,onValueChange:c,dir:f,name:S,autoComplete:w,disabled:R,required:T,form:y}=o,a=ue(l),[h,g]=t.useState(null),[m,v]=t.useState(null),[F,O]=t.useState(!1),oe=at.useDirection(f),[b=!1,D]=ke.useControllableState({prop:i,defaultProp:r,onChange:u}),[W,Y]=ke.useControllableState({prop:n,defaultProp:s,onChange:c}),L=t.useRef(null),k=h?y||!!h.closest("form"):!0,[U,V]=t.useState(new Set),B=Array.from(U).map(_=>_.props.value).join(";");return d.jsx(ee.Root,{...a,children:d.jsxs(Tt,{required:T,scope:l,trigger:h,onTriggerChange:g,valueNode:m,onValueNodeChange:v,valueNodeHasChildren:F,onValueNodeHasChildrenChange:O,contentId:Ie.useId(),value:W,onValueChange:Y,open:b,onOpenChange:D,dir:oe,triggerPointerDownPosRef:L,disabled:R,children:[d.jsx(ae.Provider,{scope:l,children:d.jsx(Pt,{scope:o.__scopeSelect,onNativeOptionAdd:t.useCallback(_=>{V(j=>new Set(j).add(_))},[]),onNativeOptionRemove:t.useCallback(_=>{V(j=>{const q=new Set(j);return q.delete(_),q})},[]),children:e})}),k?d.jsxs(ot,{"aria-hidden":!0,required:T,tabIndex:-1,name:S,autoComplete:w,value:W,onChange:_=>Y(_.target.value),disabled:R,form:y,children:[W===void 0?d.jsx("option",{value:""}):null,Array.from(U)]},B):null]})})};Te.displayName=se;var qe="SelectTrigger",Pe=t.forwardRef((o,l)=>{const{__scopeSelect:e,disabled:i=!1,...r}=o,u=ue(e),n=G(qe,e),s=n.disabled||i,c=H.useComposedRefs(l,n.onTriggerChange),f=de(e),S=t.useRef("touch"),[w,R,T]=nt(a=>{const h=f().filter(v=>!v.disabled),g=h.find(v=>v.value===n.value),m=rt(h,a,g);m!==void 0&&n.onValueChange(m.value)}),y=a=>{s||(n.onOpenChange(!0),T()),a&&(n.triggerPointerDownPosRef.current={x:Math.round(a.pageX),y:Math.round(a.pageY)})};return d.jsx(ee.Anchor,{asChild:!0,...u,children:d.jsx(M.Primitive.button,{type:"button",role:"combobox","aria-controls":n.contentId,"aria-expanded":n.open,"aria-required":n.required,"aria-autocomplete":"none",dir:n.dir,"data-state":n.open?"open":"closed",disabled:s,"data-disabled":s?"":void 0,"data-placeholder":tt(n.value)?"":void 0,...r,ref:c,onClick:E.composeEventHandlers(r.onClick,a=>{a.currentTarget.focus(),S.current!=="mouse"&&y(a)}),onPointerDown:E.composeEventHandlers(r.onPointerDown,a=>{S.current=a.pointerType;const h=a.target;h.hasPointerCapture(a.pointerId)&&h.releasePointerCapture(a.pointerId),a.button===0&&a.ctrlKey===!1&&a.pointerType==="mouse"&&(y(a),a.preventDefault())}),onKeyDown:E.composeEventHandlers(r.onKeyDown,a=>{const h=w.current!=="";!(a.ctrlKey||a.altKey||a.metaKey)&&a.key.length===1&&R(a.key),!(h&&a.key===" ")&&wt.includes(a.key)&&(y(),a.preventDefault())})})})});Pe.displayName=qe;var Fe="SelectValue",Ee=t.forwardRef((o,l)=>{const{__scopeSelect:e,className:i,style:r,children:u,placeholder:n="",...s}=o,c=G(Fe,e),{onValueNodeHasChildrenChange:f}=c,S=u!==void 0,w=H.useComposedRefs(l,c.onValueNodeChange);return $.useLayoutEffect(()=>{f(S)},[f,S]),d.jsx(M.Primitive.span,{...s,ref:w,style:{pointerEvents:"none"},children:tt(c.value)?d.jsx(d.Fragment,{children:n}):u})});Ee.displayName=Fe;var Rt="SelectIcon",Re=t.forwardRef((o,l)=>{const{__scopeSelect:e,children:i,...r}=o;return d.jsx(M.Primitive.span,{"aria-hidden":!0,...r,ref:l,children:i||"▼"})});Re.displayName=Rt;var bt="SelectPortal",be=o=>d.jsx(ft.Portal,{asChild:!0,...o});be.displayName=bt;var J="SelectContent",_e=t.forwardRef((o,l)=>{const e=G(J,o.__scopeSelect),[i,r]=t.useState();if($.useLayoutEffect(()=>{r(new DocumentFragment)},[]),!e.open){const u=i;return u?Be.createPortal(d.jsx(We,{scope:o.__scopeSelect,children:d.jsx(ae.Slot,{scope:o.__scopeSelect,children:d.jsx("div",{children:o.children})})}),u):null}return d.jsx(Ue,{...o,ref:l})});_e.displayName=J;var A=10,[We,z]=te(J),_t="SelectContentImpl",Ue=t.forwardRef((o,l)=>{const{__scopeSelect:e,position:i="item-aligned",onCloseAutoFocus:r,onEscapeKeyDown:u,onPointerDownOutside:n,side:s,sideOffset:c,align:f,alignOffset:S,arrowPadding:w,collisionBoundary:R,collisionPadding:T,sticky:y,hideWhenDetached:a,avoidCollisions:h,...g}=o,m=G(J,e),[v,F]=t.useState(null),[O,oe]=t.useState(null),b=H.useComposedRefs(l,p=>F(p)),[D,W]=t.useState(null),[Y,L]=t.useState(null),k=de(e),[U,V]=t.useState(!1),B=t.useRef(!1);t.useEffect(()=>{if(v)return gt.hideOthers(v)},[v]),ut.useFocusGuards();const _=t.useCallback(p=>{const[I,...N]=k().map(P=>P.ref.current),[x]=N.slice(-1),C=document.activeElement;for(const P of p)if(P===C||(P?.scrollIntoView({block:"nearest"}),P===I&&O&&(O.scrollTop=0),P===x&&O&&(O.scrollTop=O.scrollHeight),P?.focus(),document.activeElement!==C))return},[k,O]),j=t.useCallback(()=>_([D,v]),[_,D,v]);t.useEffect(()=>{U&&j()},[U,j]);const{onOpenChange:q,triggerPointerDownPosRef:K}=m;t.useEffect(()=>{if(v){let p={x:0,y:0};const I=x=>{p={x:Math.abs(Math.round(x.pageX)-(K.current?.x??0)),y:Math.abs(Math.round(x.pageY)-(K.current?.y??0))}},N=x=>{p.x<=10&&p.y<=10?x.preventDefault():v.contains(x.target)||q(!1),document.removeEventListener("pointermove",I),K.current=null};return K.current!==null&&(document.addEventListener("pointermove",I),document.addEventListener("pointerup",N,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",I),document.removeEventListener("pointerup",N,{capture:!0})}}},[v,q,K]),t.useEffect(()=>{const p=()=>q(!1);return window.addEventListener("blur",p),window.addEventListener("resize",p),()=>{window.removeEventListener("blur",p),window.removeEventListener("resize",p)}},[q]);const[pe,ce]=nt(p=>{const I=k().filter(C=>!C.disabled),N=I.find(C=>C.ref.current===document.activeElement),x=rt(I,p,N);x&&setTimeout(()=>x.ref.current.focus())}),fe=t.useCallback((p,I,N)=>{const x=!B.current&&!N;(m.value!==void 0&&m.value===I||x)&&(W(p),x&&(B.current=!0))},[m.value]),me=t.useCallback(()=>v?.focus(),[v]),Q=t.useCallback((p,I,N)=>{const x=!B.current&&!N;(m.value!==void 0&&m.value===I||x)&&L(p)},[m.value]),le=i==="popper"?ge:Ke,ne=le===ge?{side:s,sideOffset:c,align:f,alignOffset:S,arrowPadding:w,collisionBoundary:R,collisionPadding:T,sticky:y,hideWhenDetached:a,avoidCollisions:h}:{};return d.jsx(We,{scope:e,content:v,viewport:O,onViewportChange:oe,itemRefCallback:fe,selectedItem:D,onItemLeave:me,itemTextRefCallback:Q,focusSelectedItem:j,selectedItemText:Y,position:i,isPositioned:U,searchRef:pe,children:d.jsx(xt.default,{as:mt.Slot,allowPinchZoom:!0,children:d.jsx(pt.FocusScope,{asChild:!0,trapped:m.open,onMountAutoFocus:p=>{p.preventDefault()},onUnmountAutoFocus:E.composeEventHandlers(r,p=>{m.trigger?.focus({preventScroll:!0}),p.preventDefault()}),children:d.jsx(dt.DismissableLayer,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:u,onPointerDownOutside:n,onFocusOutside:p=>p.preventDefault(),onDismiss:()=>m.onOpenChange(!1),children:d.jsx(le,{role:"listbox",id:m.contentId,"data-state":m.open?"open":"closed",dir:m.dir,onContextMenu:p=>p.preventDefault(),...g,...ne,onPlaced:()=>V(!0),ref:b,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:E.composeEventHandlers(g.onKeyDown,p=>{const I=p.ctrlKey||p.altKey||p.metaKey;if(p.key==="Tab"&&p.preventDefault(),!I&&p.key.length===1&&ce(p.key),["ArrowUp","ArrowDown","Home","End"].includes(p.key)){let x=k().filter(C=>!C.disabled).map(C=>C.ref.current);if(["ArrowUp","End"].includes(p.key)&&(x=x.slice().reverse()),["ArrowUp","ArrowDown"].includes(p.key)){const C=p.target,P=x.indexOf(C);x=x.slice(P+1)}setTimeout(()=>_(x)),p.preventDefault()}})})})})})})});Ue.displayName=_t;var Nt="SelectItemAlignedPosition",Ke=t.forwardRef((o,l)=>{const{__scopeSelect:e,onPlaced:i,...r}=o,u=G(J,e),n=z(J,e),[s,c]=t.useState(null),[f,S]=t.useState(null),w=H.useComposedRefs(l,b=>S(b)),R=de(e),T=t.useRef(!1),y=t.useRef(!0),{viewport:a,selectedItem:h,selectedItemText:g,focusSelectedItem:m}=n,v=t.useCallback(()=>{if(u.trigger&&u.valueNode&&s&&f&&a&&h&&g){const b=u.trigger.getBoundingClientRect(),D=f.getBoundingClientRect(),W=u.valueNode.getBoundingClientRect(),Y=g.getBoundingClientRect();if(u.dir!=="rtl"){const C=Y.left-D.left,P=W.left-C,X=b.left-P,Z=b.width+X,he=Math.max(Z,D.width),ve=window.innerWidth-A,Se=Le.clamp(P,[A,Math.max(A,ve-he)]);s.style.minWidth=Z+"px",s.style.left=Se+"px"}else{const C=D.right-Y.right,P=window.innerWidth-W.right-C,X=window.innerWidth-b.right-P,Z=b.width+X,he=Math.max(Z,D.width),ve=window.innerWidth-A,Se=Le.clamp(P,[A,Math.max(A,ve-he)]);s.style.minWidth=Z+"px",s.style.right=Se+"px"}const L=R(),k=window.innerHeight-A*2,U=a.scrollHeight,V=window.getComputedStyle(f),B=parseInt(V.borderTopWidth,10),_=parseInt(V.paddingTop,10),j=parseInt(V.borderBottomWidth,10),q=parseInt(V.paddingBottom,10),K=B+_+U+q+j,pe=Math.min(h.offsetHeight*5,K),ce=window.getComputedStyle(a),fe=parseInt(ce.paddingTop,10),me=parseInt(ce.paddingBottom,10),Q=b.top+b.height/2-A,le=k-Q,ne=h.offsetHeight/2,p=h.offsetTop+ne,I=B+_+p,N=K-I;if(I<=Q){const C=L.length>0&&h===L[L.length-1].ref.current;s.style.bottom="0px";const P=f.clientHeight-a.offsetTop-a.offsetHeight,X=Math.max(le,ne+(C?me:0)+P+j),Z=I+X;s.style.height=Z+"px"}else{const C=L.length>0&&h===L[0].ref.current;s.style.top="0px";const X=Math.max(Q,B+a.offsetTop+(C?fe:0)+ne)+N;s.style.height=X+"px",a.scrollTop=I-Q+a.offsetTop}s.style.margin=`${A}px 0`,s.style.minHeight=pe+"px",s.style.maxHeight=k+"px",i?.(),requestAnimationFrame(()=>T.current=!0)}},[R,u.trigger,u.valueNode,s,f,a,h,g,u.dir,i]);$.useLayoutEffect(()=>v(),[v]);const[F,O]=t.useState();$.useLayoutEffect(()=>{f&&O(window.getComputedStyle(f).zIndex)},[f]);const oe=t.useCallback(b=>{b&&y.current===!0&&(v(),m?.(),y.current=!1)},[v,m]);return d.jsx(Ot,{scope:e,contentWrapper:s,shouldExpandOnScrollRef:T,onScrollButtonChange:oe,children:d.jsx("div",{ref:c,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:F},children:d.jsx(M.Primitive.div,{...r,ref:w,style:{boxSizing:"border-box",maxHeight:"100%",...r.style}})})})});Ke.displayName=Nt;var Mt="SelectPopperPosition",ge=t.forwardRef((o,l)=>{const{__scopeSelect:e,align:i="start",collisionPadding:r=A,...u}=o,n=ue(e);return d.jsx(ee.Content,{...n,...u,ref:l,align:i,collisionPadding:r,style:{boxSizing:"border-box",...u.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});ge.displayName=Mt;var[Ot,Ne]=te(J,{}),xe="SelectViewport",Me=t.forwardRef((o,l)=>{const{__scopeSelect:e,nonce:i,...r}=o,u=z(xe,e),n=Ne(xe,e),s=H.useComposedRefs(l,u.onViewportChange),c=t.useRef(0);return d.jsxs(d.Fragment,{children:[d.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:i}),d.jsx(ae.Slot,{scope:e,children:d.jsx(M.Primitive.div,{"data-radix-select-viewport":"",role:"presentation",...r,ref:s,style:{position:"relative",flex:1,overflow:"hidden auto",...r.style},onScroll:E.composeEventHandlers(r.onScroll,f=>{const S=f.currentTarget,{contentWrapper:w,shouldExpandOnScrollRef:R}=n;if(R?.current&&w){const T=Math.abs(c.current-S.scrollTop);if(T>0){const y=window.innerHeight-A*2,a=parseFloat(w.style.minHeight),h=parseFloat(w.style.height),g=Math.max(a,h);if(g<y){const m=g+T,v=Math.min(y,m),F=m-v;w.style.height=v+"px",w.style.bottom==="0px"&&(S.scrollTop=F>0?F:0,w.style.justifyContent="flex-end")}}}c.current=S.scrollTop})})})]})});Me.displayName=xe;var $e="SelectGroup",[At,Dt]=te($e),Ge=t.forwardRef((o,l)=>{const{__scopeSelect:e,...i}=o,r=Ie.useId();return d.jsx(At,{scope:e,id:r,children:d.jsx(M.Primitive.div,{role:"group","aria-labelledby":r,...i,ref:l})})});Ge.displayName=$e;var ze="SelectLabel",Ye=t.forwardRef((o,l)=>{const{__scopeSelect:e,...i}=o,r=Dt(ze,e);return d.jsx(M.Primitive.div,{id:r.id,...i,ref:l})});Ye.displayName=ze;var ie="SelectItem",[jt,Xe]=te(ie),Oe=t.forwardRef((o,l)=>{const{__scopeSelect:e,value:i,disabled:r=!1,textValue:u,...n}=o,s=G(ie,e),c=z(ie,e),f=s.value===i,[S,w]=t.useState(u??""),[R,T]=t.useState(!1),y=H.useComposedRefs(l,m=>c.itemRefCallback?.(m,i,r)),a=Ie.useId(),h=t.useRef("touch"),g=()=>{r||(s.onValueChange(i),s.onOpenChange(!1))};if(i==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return d.jsx(jt,{scope:e,value:i,disabled:r,textId:a,isSelected:f,onItemTextChange:t.useCallback(m=>{w(v=>v||(m?.textContent??"").trim())},[]),children:d.jsx(ae.ItemSlot,{scope:e,value:i,disabled:r,textValue:S,children:d.jsx(M.Primitive.div,{role:"option","aria-labelledby":a,"data-highlighted":R?"":void 0,"aria-selected":f&&R,"data-state":f?"checked":"unchecked","aria-disabled":r||void 0,"data-disabled":r?"":void 0,tabIndex:r?void 0:-1,...n,ref:y,onFocus:E.composeEventHandlers(n.onFocus,()=>T(!0)),onBlur:E.composeEventHandlers(n.onBlur,()=>T(!1)),onClick:E.composeEventHandlers(n.onClick,()=>{h.current!=="mouse"&&g()}),onPointerUp:E.composeEventHandlers(n.onPointerUp,()=>{h.current==="mouse"&&g()}),onPointerDown:E.composeEventHandlers(n.onPointerDown,m=>{h.current=m.pointerType}),onPointerMove:E.composeEventHandlers(n.onPointerMove,m=>{h.current=m.pointerType,r?c.onItemLeave?.():h.current==="mouse"&&m.currentTarget.focus({preventScroll:!0})}),onPointerLeave:E.composeEventHandlers(n.onPointerLeave,m=>{m.currentTarget===document.activeElement&&c.onItemLeave?.()}),onKeyDown:E.composeEventHandlers(n.onKeyDown,m=>{c.searchRef?.current!==""&&m.key===" "||(Ct.includes(m.key)&&g(),m.key===" "&&m.preventDefault())})})})})});Oe.displayName=ie;var re="SelectItemText",Ae=t.forwardRef((o,l)=>{const{__scopeSelect:e,className:i,style:r,...u}=o,n=G(re,e),s=z(re,e),c=Xe(re,e),f=Et(re,e),[S,w]=t.useState(null),R=H.useComposedRefs(l,g=>w(g),c.onItemTextChange,g=>s.itemTextRefCallback?.(g,c.value,c.disabled)),T=S?.textContent,y=t.useMemo(()=>d.jsx("option",{value:c.value,disabled:c.disabled,children:T},c.value),[c.disabled,c.value,T]),{onNativeOptionAdd:a,onNativeOptionRemove:h}=f;return $.useLayoutEffect(()=>(a(y),()=>h(y)),[a,h,y]),d.jsxs(d.Fragment,{children:[d.jsx(M.Primitive.span,{id:c.textId,...u,ref:R}),c.isSelected&&n.valueNode&&!n.valueNodeHasChildren?Be.createPortal(u.children,n.valueNode):null]})});Ae.displayName=re;var Ze="SelectItemIndicator",De=t.forwardRef((o,l)=>{const{__scopeSelect:e,...i}=o;return Xe(Ze,e).isSelected?d.jsx(M.Primitive.span,{"aria-hidden":!0,...i,ref:l}):null});De.displayName=Ze;var we="SelectScrollUpButton",je=t.forwardRef((o,l)=>{const e=z(we,o.__scopeSelect),i=Ne(we,o.__scopeSelect),[r,u]=t.useState(!1),n=H.useComposedRefs(l,i.onScrollButtonChange);return $.useLayoutEffect(()=>{if(e.viewport&&e.isPositioned){let s=function(){const f=c.scrollTop>0;u(f)};const c=e.viewport;return s(),c.addEventListener("scroll",s),()=>c.removeEventListener("scroll",s)}},[e.viewport,e.isPositioned]),r?d.jsx(Je,{...o,ref:n,onAutoScroll:()=>{const{viewport:s,selectedItem:c}=e;s&&c&&(s.scrollTop=s.scrollTop-c.offsetHeight)}}):null});je.displayName=we;var Ce="SelectScrollDownButton",He=t.forwardRef((o,l)=>{const e=z(Ce,o.__scopeSelect),i=Ne(Ce,o.__scopeSelect),[r,u]=t.useState(!1),n=H.useComposedRefs(l,i.onScrollButtonChange);return $.useLayoutEffect(()=>{if(e.viewport&&e.isPositioned){let s=function(){const f=c.scrollHeight-c.clientHeight,S=Math.ceil(c.scrollTop)<f;u(S)};const c=e.viewport;return s(),c.addEventListener("scroll",s),()=>c.removeEventListener("scroll",s)}},[e.viewport,e.isPositioned]),r?d.jsx(Je,{...o,ref:n,onAutoScroll:()=>{const{viewport:s,selectedItem:c}=e;s&&c&&(s.scrollTop=s.scrollTop+c.offsetHeight)}}):null});He.displayName=Ce;var Je=t.forwardRef((o,l)=>{const{__scopeSelect:e,onAutoScroll:i,...r}=o,u=z("SelectScrollButton",e),n=t.useRef(null),s=de(e),c=t.useCallback(()=>{n.current!==null&&(window.clearInterval(n.current),n.current=null)},[]);return t.useEffect(()=>()=>c(),[c]),$.useLayoutEffect(()=>{s().find(S=>S.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:"nearest"})},[s]),d.jsx(M.Primitive.div,{"aria-hidden":!0,...r,ref:l,style:{flexShrink:0,...r.style},onPointerDown:E.composeEventHandlers(r.onPointerDown,()=>{n.current===null&&(n.current=window.setInterval(i,50))}),onPointerMove:E.composeEventHandlers(r.onPointerMove,()=>{u.onItemLeave?.(),n.current===null&&(n.current=window.setInterval(i,50))}),onPointerLeave:E.composeEventHandlers(r.onPointerLeave,()=>{c()})})}),Ht="SelectSeparator",Qe=t.forwardRef((o,l)=>{const{__scopeSelect:e,...i}=o;return d.jsx(M.Primitive.div,{"aria-hidden":!0,...i,ref:l})});Qe.displayName=Ht;var ye="SelectArrow",et=t.forwardRef((o,l)=>{const{__scopeSelect:e,...i}=o,r=ue(e),u=G(ye,e),n=z(ye,e);return u.open&&n.position==="popper"?d.jsx(ee.Arrow,{...r,...i,ref:l}):null});et.displayName=ye;function tt(o){return o===""||o===void 0}var ot=t.forwardRef((o,l)=>{const{value:e,...i}=o,r=t.useRef(null),u=H.useComposedRefs(l,r),n=vt.usePrevious(e);return t.useEffect(()=>{const s=r.current,c=window.HTMLSelectElement.prototype,S=Object.getOwnPropertyDescriptor(c,"value").set;if(n!==e&&S){const w=new Event("change",{bubbles:!0});S.call(s,e),s.dispatchEvent(w)}},[n,e]),d.jsx(St.VisuallyHidden,{asChild:!0,children:d.jsx("select",{...i,ref:u,defaultValue:e})})});ot.displayName="BubbleSelect";function nt(o){const l=ht.useCallbackRef(o),e=t.useRef(""),i=t.useRef(0),r=t.useCallback(n=>{const s=e.current+n;l(s),function c(f){e.current=f,window.clearTimeout(i.current),f!==""&&(i.current=window.setTimeout(()=>c(""),1e3))}(s)},[l]),u=t.useCallback(()=>{e.current="",window.clearTimeout(i.current)},[]);return t.useEffect(()=>()=>window.clearTimeout(i.current),[]),[e,r,u]}function rt(o,l,e){const r=l.length>1&&Array.from(l).every(f=>f===l[0])?l[0]:l,u=e?o.indexOf(e):-1;let n=Lt(o,Math.max(u,0));r.length===1&&(n=n.filter(f=>f!==e));const c=n.find(f=>f.textValue.toLowerCase().startsWith(r.toLowerCase()));return c!==e?c:void 0}function Lt(o,l){return o.map((e,i)=>o[(l+i)%o.length])}var kt=Te,Vt=Pe,Bt=Ee,qt=Re,Ft=be,Wt=_e,Ut=Me,Kt=Oe,$t=Ae,Gt=De,zt=je,Yt=He;exports.Content=Wt;exports.Icon=qt;exports.Item=Kt;exports.ItemIndicator=Gt;exports.ItemText=$t;exports.Portal=Ft;exports.Root=kt;exports.ScrollDownButton=Yt;exports.ScrollUpButton=zt;exports.Select=Te;exports.SelectArrow=et;exports.SelectContent=_e;exports.SelectGroup=Ge;exports.SelectIcon=Re;exports.SelectItem=Oe;exports.SelectItemIndicator=De;exports.SelectItemText=Ae;exports.SelectLabel=Ye;exports.SelectPortal=be;exports.SelectScrollDownButton=He;exports.SelectScrollUpButton=je;exports.SelectSeparator=Qe;exports.SelectTrigger=Pe;exports.SelectValue=Ee;exports.SelectViewport=Me;exports.Trigger=Vt;exports.Value=Bt;exports.Viewport=Ut;exports.createSelectScope=It;
|
|
2
2
|
//# sourceMappingURL=index.cjs37.js.map
|
package/dist/index.cjs41.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("./index.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("./index.cjs55.js"),n=require("./index.cjs22.js"),r=require("./index.cjs30.js");function d({...t}){return e.jsx(o.Root,{"data-slot":"dialog",...t})}function s({...t}){return e.jsx(o.Portal,{"data-slot":"dialog-portal",...t})}function i({className:t,...a}){return e.jsx(o.Overlay,{"data-slot":"dialog-overlay",className:n.cn("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/80",t),...a})}function c({className:t,children:a,...l}){return e.jsxs(s,{"data-slot":"dialog-portal",children:[e.jsx(i,{}),e.jsxs(o.Content,{"data-slot":"dialog-content",className:n.cn("bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 sm:max-w-lg",t),...l,children:[a,e.jsxs(o.Close,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[e.jsx(r.default,{}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function g({className:t,...a}){return e.jsx("div",{"data-slot":"dialog-header",className:n.cn("flex flex-col gap-2 text-center sm:text-left",t),...a})}function u({className:t,...a}){return e.jsx("div",{"data-slot":"dialog-footer",className:n.cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",t),...a})}function f({className:t,...a}){return e.jsx(o.Title,{"data-slot":"dialog-title",className:n.cn("text-lg leading-none font-semibold",t),...a})}function x({className:t,...a}){return e.jsx(o.Description,{"data-slot":"dialog-description",className:n.cn("text-muted-foreground text-sm",t),...a})}exports.Dialog=d;exports.DialogContent=c;exports.DialogDescription=x;exports.DialogFooter=u;exports.DialogHeader=g;exports.DialogOverlay=i;exports.DialogPortal=s;exports.DialogTitle=f;
|
|
2
2
|
//# sourceMappingURL=index.cjs41.js.map
|
package/dist/index.cjs43.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index.cjs56.js"),n=require("./index.cjs22.js");function l({className:t,orientation:r="horizontal",decorative:o=!0,...a}){return e.jsx(i.Root,{"data-slot":"separator-root",decorative:o,orientation:r,className:n.cn("bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",t),...a})}exports.Separator=l;
|
|
2
2
|
//# sourceMappingURL=index.cjs43.js.map
|
package/dist/index.cjs47.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("react"),h=require("./index.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("react"),h=require("./index.cjs59.js"),R=require("./index.cjs58.js"),l=require("./index.cjs55.js"),E=require("./index.cjs57.js"),j=require("./index.cjs34.js"),i=require("react/jsx-runtime");function w(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const t=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(r,o,t.get?t:{enumerable:!0,get:()=>e[o]})}}return r.default=e,Object.freeze(r)}const n=w(T);var x="AlertDialog",[M,q]=h.createContextScope(x,[l.createDialogScope]),s=l.createDialogScope(),u=e=>{const{__scopeAlertDialog:r,...o}=e,t=s(r);return i.jsx(l.Root,{...t,...o,modal:!0})};u.displayName=x;var I="AlertDialogTrigger",C=n.forwardRef((e,r)=>{const{__scopeAlertDialog:o,...t}=e,a=s(o);return i.jsx(l.Trigger,{...a,...t,ref:r})});C.displayName=I;var $="AlertDialogPortal",A=e=>{const{__scopeAlertDialog:r,...o}=e,t=s(r);return i.jsx(l.Portal,{...t,...o})};A.displayName=$;var L="AlertDialogOverlay",D=n.forwardRef((e,r)=>{const{__scopeAlertDialog:o,...t}=e,a=s(o);return i.jsx(l.Overlay,{...a,...t,ref:r})});D.displayName=L;var c="AlertDialogContent",[F,G]=M(c),v=n.forwardRef((e,r)=>{const{__scopeAlertDialog:o,children:t,...a}=e,d=s(o),g=n.useRef(null),b=R.useComposedRefs(r,g),N=n.useRef(null);return i.jsx(l.WarningProvider,{contentName:c,titleName:S,docsSlug:"alert-dialog",children:i.jsx(F,{scope:o,cancelRef:N,children:i.jsxs(l.Content,{role:"alertdialog",...d,...a,ref:b,onOpenAutoFocus:E.composeEventHandlers(a.onOpenAutoFocus,p=>{p.preventDefault(),N.current?.focus({preventScroll:!0})}),onPointerDownOutside:p=>p.preventDefault(),onInteractOutside:p=>p.preventDefault(),children:[i.jsx(j.Slottable,{children:t}),i.jsx(Y,{contentRef:g})]})})})});v.displayName=c;var S="AlertDialogTitle",f=n.forwardRef((e,r)=>{const{__scopeAlertDialog:o,...t}=e,a=s(o);return i.jsx(l.Title,{...a,...t,ref:r})});f.displayName=S;var O="AlertDialogDescription",m=n.forwardRef((e,r)=>{const{__scopeAlertDialog:o,...t}=e,a=s(o);return i.jsx(l.Description,{...a,...t,ref:r})});m.displayName=O;var W="AlertDialogAction",y=n.forwardRef((e,r)=>{const{__scopeAlertDialog:o,...t}=e,a=s(o);return i.jsx(l.Close,{...a,...t,ref:r})});y.displayName=W;var P="AlertDialogCancel",_=n.forwardRef((e,r)=>{const{__scopeAlertDialog:o,...t}=e,{cancelRef:a}=G(P,o),d=s(o),g=R.useComposedRefs(r,a);return i.jsx(l.Close,{...d,...t,ref:g})});_.displayName=P;var Y=({contentRef:e})=>{const r=`\`${c}\` requires a description for the component to be accessible for screen reader users.
|
|
2
2
|
|
|
3
3
|
You can add a description to the \`${c}\` by passing a \`${O}\` component as a child, which also benefits sighted users by adding visible context to the dialog.
|
|
4
4
|
|
package/dist/index.cjs55.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("react"),f=require("./index.cjs57.js"),C=require("./index.cjs58.js"),M=require("./index.cjs59.js"),m=require("./index.cjs70.js"),B=require("./index.cjs60.js"),V=require("./index.cjs67.js"),z=require("./index.cjs69.js"),K=require("./index.cjs72.js"),R=require("./index.cjs82.js"),p=require("./index.cjs63.js"),U=require("./index.cjs68.js"),Y=require("./index.cjs77.js"),Z=require("./index.cjs76.js"),J=require("./index.cjs34.js"),s=require("react/jsx-runtime");function Q(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const r=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,r.get?r:{enumerable:!0,get:()=>e[o]})}}return t.default=e,Object.freeze(t)}const a=Q(H);var P="Dialog",[S,X]=M.createContextScope(P),[ee,u]=S(P),_=e=>{const{__scopeDialog:t,children:o,open:r,defaultOpen:i,onOpenChange:n,modal:l=!0}=e,c=a.useRef(null),g=a.useRef(null),[v=!1,x]=B.useControllableState({prop:r,defaultProp:i,onChange:n});return s.jsx(ee,{scope:t,triggerRef:c,contentRef:g,contentId:m.useId(),titleId:m.useId(),descriptionId:m.useId(),open:v,onOpenChange:x,onOpenToggle:a.useCallback(()=>x(L=>!L),[x]),modal:l,children:o})};_.displayName=P;var w="DialogTrigger",y=a.forwardRef((e,t)=>{const{__scopeDialog:o,...r}=e,i=u(w,o),n=C.useComposedRefs(t,i.triggerRef);return s.jsx(p.Primitive.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":A(i.open),...r,ref:n,onClick:f.composeEventHandlers(e.onClick,i.onOpenToggle)})});y.displayName=w;var E="DialogPortal",[te,F]=S(E,{forceMount:void 0}),O=e=>{const{__scopeDialog:t,forceMount:o,children:r,container:i}=e,n=u(E,t);return s.jsx(te,{scope:t,forceMount:o,children:a.Children.map(r,l=>s.jsx(R.Presence,{present:o||n.open,children:s.jsx(K.Portal,{asChild:!0,container:i,children:l})}))})};O.displayName=E;var D="DialogOverlay",h=a.forwardRef((e,t)=>{const o=F(D,e.__scopeDialog),{forceMount:r=o.forceMount,...i}=e,n=u(D,e.__scopeDialog);return n.modal?s.jsx(R.Presence,{present:r||n.open,children:s.jsx(oe,{...i,ref:t})}):null});h.displayName=D;var oe=a.forwardRef((e,t)=>{const{__scopeDialog:o,...r}=e,i=u(D,o);return s.jsx(Y.default,{as:J.Slot,allowPinchZoom:!0,shards:[i.contentRef],children:s.jsx(p.Primitive.div,{"data-state":A(i.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),d="DialogContent",N=a.forwardRef((e,t)=>{const o=F(d,e.__scopeDialog),{forceMount:r=o.forceMount,...i}=e,n=u(d,e.__scopeDialog);return s.jsx(R.Presence,{present:r||n.open,children:n.modal?s.jsx(ne,{...i,ref:t}):s.jsx(re,{...i,ref:t})})});N.displayName=d;var ne=a.forwardRef((e,t)=>{const o=u(d,e.__scopeDialog),r=a.useRef(null),i=C.useComposedRefs(t,o.contentRef,r);return a.useEffect(()=>{const n=r.current;if(n)return Z.hideOthers(n)},[]),s.jsx(q,{...e,ref:i,trapFocus:o.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:f.composeEventHandlers(e.onCloseAutoFocus,n=>{n.preventDefault(),o.triggerRef.current?.focus()}),onPointerDownOutside:f.composeEventHandlers(e.onPointerDownOutside,n=>{const l=n.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0;(l.button===2||c)&&n.preventDefault()}),onFocusOutside:f.composeEventHandlers(e.onFocusOutside,n=>n.preventDefault())})}),re=a.forwardRef((e,t)=>{const o=u(d,e.__scopeDialog),r=a.useRef(!1),i=a.useRef(!1);return s.jsx(q,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:n=>{e.onCloseAutoFocus?.(n),n.defaultPrevented||(r.current||o.triggerRef.current?.focus(),n.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:n=>{e.onInteractOutside?.(n),n.defaultPrevented||(r.current=!0,n.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const l=n.target;o.triggerRef.current?.contains(l)&&n.preventDefault(),n.detail.originalEvent.type==="focusin"&&i.current&&n.preventDefault()}})}),q=a.forwardRef((e,t)=>{const{__scopeDialog:o,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:n,...l}=e,c=u(d,o),g=a.useRef(null),v=C.useComposedRefs(t,g);return U.useFocusGuards(),s.jsxs(s.Fragment,{children:[s.jsx(z.FocusScope,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:n,children:s.jsx(V.DismissableLayer,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":A(c.open),...l,ref:v,onDismiss:()=>c.onOpenChange(!1)})}),s.jsxs(s.Fragment,{children:[s.jsx(se,{titleId:c.titleId}),s.jsx(ce,{contentRef:g,descriptionId:c.descriptionId})]})]})}),b="DialogTitle",I=a.forwardRef((e,t)=>{const{__scopeDialog:o,...r}=e,i=u(b,o);return s.jsx(p.Primitive.h2,{id:i.titleId,...r,ref:t})});I.displayName=b;var $="DialogDescription",T=a.forwardRef((e,t)=>{const{__scopeDialog:o,...r}=e,i=u($,o);return s.jsx(p.Primitive.p,{id:i.descriptionId,...r,ref:t})});T.displayName=$;var W="DialogClose",j=a.forwardRef((e,t)=>{const{__scopeDialog:o,...r}=e,i=u(W,o);return s.jsx(p.Primitive.button,{type:"button",...r,ref:t,onClick:f.composeEventHandlers(e.onClick,()=>i.onOpenChange(!1))})});j.displayName=W;function A(e){return e?"open":"closed"}var k="DialogTitleWarning",[ie,G]=M.createContext(k,{contentName:d,titleName:b,docsSlug:"dialog"}),se=({titleId:e})=>{const t=G(k),o=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
2
|
+
|
|
3
|
+
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
4
|
+
|
|
5
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return a.useEffect(()=>{e&&(document.getElementById(e)||console.error(o))},[o,e]),null},ae="DialogDescriptionWarning",ce=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${G(ae).contentName}}.`;return a.useEffect(()=>{const i=e.current?.getAttribute("aria-describedby");t&&i&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},le=_,ue=y,de=O,ge=h,fe=N,pe=I,De=T,ve=j;exports.Close=ve;exports.Content=fe;exports.Description=De;exports.Dialog=_;exports.DialogClose=j;exports.DialogContent=N;exports.DialogDescription=T;exports.DialogOverlay=h;exports.DialogPortal=O;exports.DialogTitle=I;exports.DialogTrigger=y;exports.Overlay=ge;exports.Portal=de;exports.Root=le;exports.Title=pe;exports.Trigger=ue;exports.WarningProvider=ie;exports.createDialogScope=X;
|
|
2
6
|
//# sourceMappingURL=index.cjs55.js.map
|