UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

133 lines (132 loc) • 5.59 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var composeFamilyValidation_exports = {}; __export(composeFamilyValidation_exports, { composeRangeDay: () => composeRangeDay, validateComposeFamily: () => validateComposeFamily }); module.exports = __toCommonJS(composeFamilyValidation_exports); var import_syncStore = require("./syncStore.cjs"); var import_composeValidation = require("./composeValidation.cjs"); function composeRangeDay(date) { return Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()); } function localRangeDay(date) { return new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()); } function validateComposeFamily(kind, props) { const fail = (key) => { throw new Error(`Compose ${kind} invalid ${key}`); }; const number = (key, minimum = 0, maximum = Infinity) => { const value = props[key]; if (value !== void 0 && (typeof value !== "number" || !Number.isFinite(value) || value < minimum || value > maximum)) fail(key); }; const boolean = (key) => { if (props[key] !== void 0 && typeof props[key] !== "boolean") fail(key); }; const callback = (key) => { if (props[key] !== void 0 && typeof props[key] !== "function") fail(key); }; if (kind.endsWith("carousel")) { for (const key of [ "maxItemWidth", "preferredItemWidth", "itemWidth", "minSmallItemWidth", "maxSmallItemWidth" ]) number(key, Number.MIN_VALUE); number("itemSpacing"); boolean("userScrollEnabled"); if (kind === "multibrowsecarousel" && props.preferredItemWidth === void 0) fail("preferredItemWidth"); if (kind === "uncontainedcarousel" && props.itemWidth === void 0) fail("itemWidth"); if (props.minSmallItemWidth !== void 0 && props.maxSmallItemWidth !== void 0 && props.minSmallItemWidth > props.maxSmallItemWidth) fail("small item widths"); if (props.flingBehavior !== void 0 && !["singleAdvance", "noSnap"].includes(props.flingBehavior)) fail("flingBehavior"); if (typeof props.contentPadding === "number") { if (!Number.isFinite(props.contentPadding) || props.contentPadding < 0) fail("contentPadding"); } else if (props.contentPadding !== void 0) { if (!props.contentPadding || typeof props.contentPadding !== "object") fail("contentPadding"); for (const value of Object.values(props.contentPadding)) if (typeof value !== "number" || !Number.isFinite(value) || value < 0) fail("contentPadding"); } } else if (kind === "shape") { for (const key of [ "smoothing", "cornerRounding", "innerRadius", "radius" ]) number(key, 0, 1); number("verticesCount", 3); if (props.verticesCount !== void 0 && !Number.isInteger(props.verticesCount)) fail("verticesCount"); for (const key of [ "topStart", "topEnd", "bottomStart", "bottomEnd" ]) number(key); } else if (kind === "dialog") { callback("onDismissRequest"); if (props.properties !== void 0) { if (!props.properties || typeof props.properties !== "object") fail("properties"); for (const [key, value] of Object.entries(props.properties)) { if (![ "dismissOnBackPress", "dismissOnClickOutside", "usePlatformDefaultWidth", "decorFitsSystemWindows" ].includes(key) || typeof value !== "boolean") fail(key); } } } else if (kind === "toolbar") { if (props.variant !== void 0 && !["standard", "vibrant"].includes(props.variant)) fail("variant"); } else if (kind === "syncswitch") { if (!(0, import_syncStore.isSyncState)(props.isOn) || typeof props.isOn.value !== "boolean") fail("isOn (requires NativeState<boolean>)"); boolean("enabled"); } else if (kind === "range") { const date = (key) => { const value = props[key]; if (value == null) return void 0; if (typeof value !== "string" || !Number.isFinite(new Date(value).getTime())) fail(key); return new Date(value); }; const start = date("initialStartDate"); const end = date("initialEndDate"); if (end && (!start || composeRangeDay(end) < composeRangeDay(start))) fail("initialEndDate"); callback("onDateRangeSelected"); for (const key of [ "showTitle", "showHeadline", "showVariantToggle" ]) boolean(key); (0, import_composeValidation.validateDatePickerProps)({ selection: localRangeDay(start ?? props.selectableDates?.start ?? props.selectableDates?.end ?? /* @__PURE__ */ new Date()), minimumDate: props.selectableDates?.start && localRangeDay(props.selectableDates.start), maximumDate: props.selectableDates?.end && localRangeDay(props.selectableDates.end), variant: props.variant, colors: props.elementColors, color: props.color }); if (end) (0, import_composeValidation.validateDatePickerProps)({ selection: localRangeDay(end), minimumDate: props.selectableDates?.start && localRangeDay(props.selectableDates.start), maximumDate: props.selectableDates?.end && localRangeDay(props.selectableDates.end) }); } }