@fluid-app/rep-core 0.1.0
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/chunk-6QLUUNJL.cjs +153 -0
- package/dist/chunk-6QLUUNJL.cjs.map +1 -0
- package/dist/chunk-EWR5EIBP.js +136 -0
- package/dist/chunk-EWR5EIBP.js.map +1 -0
- package/dist/data-sources/context.cjs +26 -0
- package/dist/data-sources/context.cjs.map +1 -0
- package/dist/data-sources/context.d.cts +16 -0
- package/dist/data-sources/context.d.ts +16 -0
- package/dist/data-sources/context.js +23 -0
- package/dist/data-sources/context.js.map +1 -0
- package/dist/data-sources/types.cjs +4 -0
- package/dist/data-sources/types.cjs.map +1 -0
- package/dist/data-sources/types.d.cts +122 -0
- package/dist/data-sources/types.d.ts +122 -0
- package/dist/data-sources/types.js +3 -0
- package/dist/data-sources/types.js.map +1 -0
- package/dist/registries/index.cjs +156 -0
- package/dist/registries/index.cjs.map +1 -0
- package/dist/registries/index.d.cts +303 -0
- package/dist/registries/index.d.ts +303 -0
- package/dist/registries/index.js +143 -0
- package/dist/registries/index.js.map +1 -0
- package/dist/shareable-item-DPmNZkE1.d.cts +138 -0
- package/dist/shareable-item-DPmNZkE1.d.ts +138 -0
- package/dist/theme/index.cjs +1013 -0
- package/dist/theme/index.cjs.map +1 -0
- package/dist/theme/index.d.cts +2680 -0
- package/dist/theme/index.d.ts +2680 -0
- package/dist/theme/index.js +956 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/theme-DrMUYZTO.d.cts +22 -0
- package/dist/theme-DrMUYZTO.d.ts +22 -0
- package/dist/types/index.cjs +72 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +227 -0
- package/dist/types/index.d.ts +227 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/widget-utils/index.cjs +123 -0
- package/dist/widget-utils/index.cjs.map +1 -0
- package/dist/widget-utils/index.d.cts +43 -0
- package/dist/widget-utils/index.d.ts +43 -0
- package/dist/widget-utils/index.js +111 -0
- package/dist/widget-utils/index.js.map +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/types/widget-schema.ts
|
|
4
|
+
var WIDGET_TYPE_NAMES = {
|
|
5
|
+
Alert: "AlertWidget",
|
|
6
|
+
Calendar: "CalendarWidget",
|
|
7
|
+
Carousel: "CarouselWidget",
|
|
8
|
+
CatchUp: "CatchUpWidget",
|
|
9
|
+
Chart: "ChartWidget",
|
|
10
|
+
Container: "ContainerWidget",
|
|
11
|
+
Embed: "EmbedWidget",
|
|
12
|
+
Image: "ImageWidget",
|
|
13
|
+
Layout: "LayoutWidget",
|
|
14
|
+
List: "ListWidget",
|
|
15
|
+
MySite: "MySiteWidget",
|
|
16
|
+
Nested: "NestedWidget",
|
|
17
|
+
QuickShare: "QuickShareWidget",
|
|
18
|
+
RecentActivity: "RecentActivityWidget",
|
|
19
|
+
Spacer: "SpacerWidget",
|
|
20
|
+
Table: "TableWidget",
|
|
21
|
+
Text: "TextWidget",
|
|
22
|
+
ToDo: "ToDoWidget",
|
|
23
|
+
Video: "VideoWidget"
|
|
24
|
+
};
|
|
25
|
+
function isWidgetTypeName(type) {
|
|
26
|
+
return Object.values(WIDGET_TYPE_NAMES).includes(type);
|
|
27
|
+
}
|
|
28
|
+
function isWidgetType(widget, typeName) {
|
|
29
|
+
return widget != null && widget.type === typeName;
|
|
30
|
+
}
|
|
31
|
+
function assertNever(value, context) {
|
|
32
|
+
const message = context ? `Unexpected ${context}: ${String(value)}` : `Unexpected value: ${String(value)}`;
|
|
33
|
+
throw new Error(message);
|
|
34
|
+
}
|
|
35
|
+
function assertDefined(value, name) {
|
|
36
|
+
if (value == null) {
|
|
37
|
+
throw new Error(name ? `${name} is required` : "Value is required");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/types/field-types.ts
|
|
42
|
+
var COLOR_OPTIONS = {
|
|
43
|
+
background: "background",
|
|
44
|
+
foreground: "foreground",
|
|
45
|
+
primary: "primary",
|
|
46
|
+
secondary: "secondary",
|
|
47
|
+
accent: "accent",
|
|
48
|
+
muted: "muted",
|
|
49
|
+
destructive: "destructive"
|
|
50
|
+
};
|
|
51
|
+
var FONT_SIZE_OPTIONS = {
|
|
52
|
+
"2xl": "2xl",
|
|
53
|
+
xl: "xl",
|
|
54
|
+
lg: "lg",
|
|
55
|
+
md: "md",
|
|
56
|
+
sm: "sm",
|
|
57
|
+
xs: "xs"
|
|
58
|
+
};
|
|
59
|
+
var BORDER_RADIUS_OPTIONS = {
|
|
60
|
+
none: "none",
|
|
61
|
+
sm: "sm",
|
|
62
|
+
md: "md",
|
|
63
|
+
lg: "lg",
|
|
64
|
+
xl: "xl",
|
|
65
|
+
full: "full"
|
|
66
|
+
};
|
|
67
|
+
var PADDING_VALUES = [0, 2, 4, 6, 8, 10];
|
|
68
|
+
var BUTTON_SIZE_OPTIONS = {
|
|
69
|
+
sm: "sm",
|
|
70
|
+
default: "default",
|
|
71
|
+
lg: "lg",
|
|
72
|
+
xl: "xl"
|
|
73
|
+
};
|
|
74
|
+
var GAP_OPTIONS = {
|
|
75
|
+
none: "none",
|
|
76
|
+
xs: "xs",
|
|
77
|
+
sm: "sm",
|
|
78
|
+
md: "md",
|
|
79
|
+
lg: "lg",
|
|
80
|
+
xl: "xl"
|
|
81
|
+
};
|
|
82
|
+
var VERTICAL_ALIGN_OPTIONS = {
|
|
83
|
+
top: "top",
|
|
84
|
+
center: "center",
|
|
85
|
+
bottom: "bottom"
|
|
86
|
+
};
|
|
87
|
+
var HORIZONTAL_ALIGN_OPTIONS = {
|
|
88
|
+
left: "left",
|
|
89
|
+
center: "center",
|
|
90
|
+
right: "right"
|
|
91
|
+
};
|
|
92
|
+
var BACKGROUND_TYPES = {
|
|
93
|
+
solid: "solid",
|
|
94
|
+
image: "image"
|
|
95
|
+
};
|
|
96
|
+
var SECTION_LAYOUT_CONFIG = {
|
|
97
|
+
"single-column": { columns: 1, widths: ["1fr"], gridClasses: "" },
|
|
98
|
+
"2c-equal": {
|
|
99
|
+
columns: 2,
|
|
100
|
+
widths: ["1fr", "1fr"],
|
|
101
|
+
gridClasses: "@md:grid-cols-2"
|
|
102
|
+
},
|
|
103
|
+
"2c-left-wider": {
|
|
104
|
+
columns: 2,
|
|
105
|
+
widths: ["2fr", "1fr"],
|
|
106
|
+
gridClasses: "@md:grid-cols-[2fr_1fr]"
|
|
107
|
+
},
|
|
108
|
+
"2c-right-wider": {
|
|
109
|
+
columns: 2,
|
|
110
|
+
widths: ["1fr", "2fr"],
|
|
111
|
+
gridClasses: "@md:grid-cols-[1fr_2fr]"
|
|
112
|
+
},
|
|
113
|
+
"2c-left-narrow": {
|
|
114
|
+
columns: 2,
|
|
115
|
+
widths: ["1fr", "3fr"],
|
|
116
|
+
gridClasses: "@md:grid-cols-[1fr_3fr]"
|
|
117
|
+
},
|
|
118
|
+
"2c-right-narrow": {
|
|
119
|
+
columns: 2,
|
|
120
|
+
widths: ["3fr", "1fr"],
|
|
121
|
+
gridClasses: "@md:grid-cols-[3fr_1fr]"
|
|
122
|
+
},
|
|
123
|
+
"3c-equal": {
|
|
124
|
+
columns: 3,
|
|
125
|
+
widths: ["1fr", "1fr", "1fr"],
|
|
126
|
+
gridClasses: "@md:grid-cols-3"
|
|
127
|
+
},
|
|
128
|
+
"3c-middle-wider": {
|
|
129
|
+
columns: 3,
|
|
130
|
+
widths: ["1fr", "2fr", "1fr"],
|
|
131
|
+
gridClasses: "@md:grid-cols-[1fr_2fr_1fr]"
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
var sectionLayoutConfig = SECTION_LAYOUT_CONFIG;
|
|
135
|
+
|
|
136
|
+
exports.BACKGROUND_TYPES = BACKGROUND_TYPES;
|
|
137
|
+
exports.BORDER_RADIUS_OPTIONS = BORDER_RADIUS_OPTIONS;
|
|
138
|
+
exports.BUTTON_SIZE_OPTIONS = BUTTON_SIZE_OPTIONS;
|
|
139
|
+
exports.COLOR_OPTIONS = COLOR_OPTIONS;
|
|
140
|
+
exports.FONT_SIZE_OPTIONS = FONT_SIZE_OPTIONS;
|
|
141
|
+
exports.GAP_OPTIONS = GAP_OPTIONS;
|
|
142
|
+
exports.HORIZONTAL_ALIGN_OPTIONS = HORIZONTAL_ALIGN_OPTIONS;
|
|
143
|
+
exports.PADDING_VALUES = PADDING_VALUES;
|
|
144
|
+
exports.SECTION_LAYOUT_CONFIG = SECTION_LAYOUT_CONFIG;
|
|
145
|
+
exports.VERTICAL_ALIGN_OPTIONS = VERTICAL_ALIGN_OPTIONS;
|
|
146
|
+
exports.WIDGET_TYPE_NAMES = WIDGET_TYPE_NAMES;
|
|
147
|
+
exports.assertDefined = assertDefined;
|
|
148
|
+
exports.assertNever = assertNever;
|
|
149
|
+
exports.isWidgetType = isWidgetType;
|
|
150
|
+
exports.isWidgetTypeName = isWidgetTypeName;
|
|
151
|
+
exports.sectionLayoutConfig = sectionLayoutConfig;
|
|
152
|
+
//# sourceMappingURL=chunk-6QLUUNJL.cjs.map
|
|
153
|
+
//# sourceMappingURL=chunk-6QLUUNJL.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/widget-schema.ts","../src/types/field-types.ts"],"names":[],"mappings":";;;AAOO,IAAM,iBAAA,GAAoB;AAAA,EAC/B,KAAA,EAAO,aAAA;AAAA,EACP,QAAA,EAAU,gBAAA;AAAA,EACV,QAAA,EAAU,gBAAA;AAAA,EACV,OAAA,EAAS,eAAA;AAAA,EACT,KAAA,EAAO,aAAA;AAAA,EACP,SAAA,EAAW,iBAAA;AAAA,EACX,KAAA,EAAO,aAAA;AAAA,EACP,KAAA,EAAO,aAAA;AAAA,EACP,MAAA,EAAQ,cAAA;AAAA,EACR,IAAA,EAAM,YAAA;AAAA,EACN,MAAA,EAAQ,cAAA;AAAA,EACR,MAAA,EAAQ,cAAA;AAAA,E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V,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,CAAC,KAAA,EAAO,KAAK,CAAA;AAAA,IACrB,WAAA,EAAa;AAAA,GACf;AAAA,EACA,eAAA,EAAiB;AAAA,IACf,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,CAAC,KAAA,EAAO,KAAK,CAAA;AAAA,IACrB,WAAA,EAAa;AAAA,GACf;AAAA,EACA,gBAAA,EAAkB;AAAA,IAChB,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,CAAC,KAAA,EAAO,KAAK,CAAA;AAAA,IACrB,WAAA,EAAa;AAAA,GACf;AAAA,EACA,gBAAA,EAAkB;AAAA,IAChB,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,CAAC,KAAA,EAAO,KAAK,CAAA;AAAA,IACrB,WAAA,EAAa;AAAA,GACf;AAAA,EACA,iBAAA,EAAmB;AAAA,IACjB,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,CAAC,KAAA,EAAO,KAAK,CAAA;AAAA,IACrB,WAAA,EAAa;AAAA,GACf;AAAA,EACA,UAAA,EAAY;AAAA,IACV,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,CAAC,KAAA,EAAO,KAAA,EAAO,KAAK,CAAA;AAAA,IAC5B,WAAA,EAAa;AAAA,GACf;AAAA,EACA,iBAAA,EAAmB;AAAA,IACjB,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,CAAC,KAAA,EAAO,KAAA,EAAO,KAAK,CAAA;AAAA,IAC5B,WAAA,EAAa;AAAA;AAEjB;AAgBO,IAAM,mBAAA,GAAsB","file":"chunk-6QLUUNJL.cjs","sourcesContent":["import type { ComponentType } from \"react\";\n\n/**\n * Widget type names as a const object.\n * This serves as the single source of truth for widget discriminants.\n * Use `as const` for literal type inference (safety-as-const-deep-readonly rule).\n */\nexport const WIDGET_TYPE_NAMES = {\n Alert: \"AlertWidget\",\n Calendar: \"CalendarWidget\",\n Carousel: \"CarouselWidget\",\n CatchUp: \"CatchUpWidget\",\n Chart: \"ChartWidget\",\n Container: \"ContainerWidget\",\n Embed: \"EmbedWidget\",\n Image: \"ImageWidget\",\n Layout: \"LayoutWidget\",\n List: \"ListWidget\",\n MySite: \"MySiteWidget\",\n Nested: \"NestedWidget\",\n QuickShare: \"QuickShareWidget\",\n RecentActivity: \"RecentActivityWidget\",\n Spacer: \"SpacerWidget\",\n Table: \"TableWidget\",\n Text: \"TextWidget\",\n ToDo: \"ToDoWidget\",\n Video: \"VideoWidget\",\n} as const;\n\n/**\n * Union of all known widget type names.\n * Derived from WIDGET_TYPE_NAMES to avoid duplication (deriving-typeof-for-object-keys rule).\n */\nexport type WidgetTypeName =\n (typeof WIDGET_TYPE_NAMES)[keyof typeof WIDGET_TYPE_NAMES];\n\n/**\n * Legacy alias for backwards compatibility.\n * Prefer using WidgetTypeName for new code when you need the union type.\n */\nexport type WidgetType = string;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type WidgetRegistry = Record<WidgetType, ComponentType<any>>;\n\n/**\n * Base widget schema with loose typing for runtime data.\n * Use TypedWidgetSchema<T> when you have a known registry for better type safety.\n */\nexport type WidgetSchema = {\n readonly type: WidgetType;\n readonly props: Readonly<Record<string, unknown>>;\n readonly id?: string; // Optional unique identifier for drag-and-drop\n /** Column index for masonry layouts (0-indexed) */\n readonly columnIndex?: number;\n};\n\n/**\n * Type-safe widget schema based on registry.\n * Uses discriminated unions - the `type` field serves as discriminant.\n * When narrowed (e.g., `if (widget.type === \"AlertWidget\")`),\n * TypeScript automatically knows the correct props type.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type TypedWidgetSchema<T extends Record<string, ComponentType<any>>> = {\n [K in keyof T]: {\n readonly type: K;\n readonly props: Readonly<React.ComponentProps<T[K]>>;\n readonly id?: string;\n /** Column index for masonry layouts (0-indexed) */\n readonly columnIndex?: number;\n };\n}[keyof T];\n\n/**\n * Widget path in the tree - array of indices.\n * Readonly tuple to prevent accidental mutation.\n */\nexport type WidgetPath = readonly number[];\n\n// ============================================================================\n// Type Guards and Assertion Functions\n// ============================================================================\n\n/**\n * Type predicate to check if a string is a known widget type name.\n * Use for runtime validation of widget types.\n *\n * @example\n * if (isWidgetTypeName(widget.type)) {\n * // TypeScript knows widget.type is WidgetTypeName\n * }\n */\nexport function isWidgetTypeName(type: string): type is WidgetTypeName {\n // Type assertion required in type guard: Object.values() returns string[], but we\n // need to check against WidgetTypeName values. The assertion is safe because we're\n // checking membership, and the return type predicate ensures correct narrowing.\n return Object.values(WIDGET_TYPE_NAMES).includes(type as WidgetTypeName);\n}\n\n/**\n * Type predicate to check if a widget has a specific type.\n * Enables type-safe widget narrowing without `as` assertions.\n *\n * @example\n * if (isWidgetType(widget, \"LayoutWidget\")) {\n * // TypeScript knows widget.type === \"LayoutWidget\"\n * // and widget.props is LayoutWidget props\n * }\n */\nexport function isWidgetType<T extends WidgetTypeName>(\n widget: WidgetSchema | null | undefined,\n typeName: T,\n): widget is WidgetSchema & { readonly type: T } {\n return widget != null && widget.type === typeName;\n}\n\n/**\n * Helper for exhaustive switch statements on widget types.\n * Use in the default case to ensure all widget types are handled.\n *\n * @example\n * switch (widget.type) {\n * case \"AlertWidget\": return handleAlert();\n * case \"TextWidget\": return handleText();\n * // ... all other widget types\n * default: return assertNever(widget.type, \"widget type\");\n * }\n */\nexport function assertNever(value: never, context?: string): never {\n const message = context\n ? `Unexpected ${context}: ${String(value)}`\n : `Unexpected value: ${String(value)}`;\n throw new Error(message);\n}\n\n/**\n * Assertion function that throws if value is undefined.\n * Narrows the type to exclude undefined.\n *\n * @example\n * const widget = screen[0];\n * assertDefined(widget, \"widget at index 0\");\n * // TypeScript knows widget is defined here\n */\nexport function assertDefined<T>(\n value: T | undefined | null,\n name?: string,\n): asserts value is T {\n if (value == null) {\n throw new Error(name ? `${name} is required` : \"Value is required\");\n }\n}\n","import type { ShareableItem } from \"./shareable-item\";\n\n// ============================================================================\n// Color Options - Derive type from constant for single source of truth\n// ============================================================================\n\n/**\n * Color options constant - single source of truth for color values.\n * Use COLOR_OPTIONS.primary instead of \"primary\" for type-safe comparisons.\n */\nexport const COLOR_OPTIONS = {\n background: \"background\",\n foreground: \"foreground\",\n primary: \"primary\",\n secondary: \"secondary\",\n accent: \"accent\",\n muted: \"muted\",\n destructive: \"destructive\",\n} as const;\n\n/**\n * Union type of all color options, derived from COLOR_OPTIONS constant.\n * @see deriving-typeof-for-object-keys pattern\n */\nexport type ColorOptions = (typeof COLOR_OPTIONS)[keyof typeof COLOR_OPTIONS];\n\n// ============================================================================\n// Size Options - Derive types from constants for single source of truth\n// ============================================================================\n\nexport const FONT_SIZE_OPTIONS = {\n \"2xl\": \"2xl\",\n xl: \"xl\",\n lg: \"lg\",\n md: \"md\",\n sm: \"sm\",\n xs: \"xs\",\n} as const;\n\nexport type FontSizeOptions =\n (typeof FONT_SIZE_OPTIONS)[keyof typeof FONT_SIZE_OPTIONS];\n\nexport const BORDER_RADIUS_OPTIONS = {\n none: \"none\",\n sm: \"sm\",\n md: \"md\",\n lg: \"lg\",\n xl: \"xl\",\n full: \"full\",\n} as const;\n\nexport type BorderRadiusOptions =\n (typeof BORDER_RADIUS_OPTIONS)[keyof typeof BORDER_RADIUS_OPTIONS];\n\n/** Padding values - numeric, so we use a tuple for derivation */\nexport const PADDING_VALUES = [0, 2, 4, 6, 8, 10] as const;\nexport type PaddingOptions = (typeof PADDING_VALUES)[number];\n\nexport const BUTTON_SIZE_OPTIONS = {\n sm: \"sm\",\n default: \"default\",\n lg: \"lg\",\n xl: \"xl\",\n} as const;\n\nexport type ButtonSizeOptions =\n (typeof BUTTON_SIZE_OPTIONS)[keyof typeof BUTTON_SIZE_OPTIONS];\n\nexport const GAP_OPTIONS = {\n none: \"none\",\n xs: \"xs\",\n sm: \"sm\",\n md: \"md\",\n lg: \"lg\",\n xl: \"xl\",\n} as const;\n\nexport type GapOptions = (typeof GAP_OPTIONS)[keyof typeof GAP_OPTIONS];\n\n// ============================================================================\n// Alignment Options - Derive from constants\n// ============================================================================\n\nexport const VERTICAL_ALIGN_OPTIONS = {\n top: \"top\",\n center: \"center\",\n bottom: \"bottom\",\n} as const;\n\nexport type VerticalAlign =\n (typeof VERTICAL_ALIGN_OPTIONS)[keyof typeof VERTICAL_ALIGN_OPTIONS];\n\nexport const HORIZONTAL_ALIGN_OPTIONS = {\n left: \"left\",\n center: \"center\",\n right: \"right\",\n} as const;\n\nexport type HorizontalAlign =\n (typeof HORIZONTAL_ALIGN_OPTIONS)[keyof typeof HORIZONTAL_ALIGN_OPTIONS];\n\nexport type AlignOptions = {\n vertical?: VerticalAlign;\n horizontal?: HorizontalAlign;\n};\n\n// ============================================================================\n// Background Options - Derive from constant\n// ============================================================================\n\nexport const BACKGROUND_TYPES = {\n solid: \"solid\",\n image: \"image\",\n} as const;\n\nexport type BackgroundType =\n (typeof BACKGROUND_TYPES)[keyof typeof BACKGROUND_TYPES];\nexport interface BackgroundValue {\n type: BackgroundType;\n color?: ColorOptions;\n resource?: ShareableItem;\n}\n\n// ============================================================================\n// Section Layout - Derive type from config keys (single source of truth)\n// ============================================================================\n\n/**\n * Section layout configuration - single source of truth for layout types.\n * SectionLayoutType is derived from these keys to prevent drift.\n */\nexport const SECTION_LAYOUT_CONFIG = {\n \"single-column\": { columns: 1, widths: [\"1fr\"], gridClasses: \"\" },\n \"2c-equal\": {\n columns: 2,\n widths: [\"1fr\", \"1fr\"],\n gridClasses: \"@md:grid-cols-2\",\n },\n \"2c-left-wider\": {\n columns: 2,\n widths: [\"2fr\", \"1fr\"],\n gridClasses: \"@md:grid-cols-[2fr_1fr]\",\n },\n \"2c-right-wider\": {\n columns: 2,\n widths: [\"1fr\", \"2fr\"],\n gridClasses: \"@md:grid-cols-[1fr_2fr]\",\n },\n \"2c-left-narrow\": {\n columns: 2,\n widths: [\"1fr\", \"3fr\"],\n gridClasses: \"@md:grid-cols-[1fr_3fr]\",\n },\n \"2c-right-narrow\": {\n columns: 2,\n widths: [\"3fr\", \"1fr\"],\n gridClasses: \"@md:grid-cols-[3fr_1fr]\",\n },\n \"3c-equal\": {\n columns: 3,\n widths: [\"1fr\", \"1fr\", \"1fr\"],\n gridClasses: \"@md:grid-cols-3\",\n },\n \"3c-middle-wider\": {\n columns: 3,\n widths: [\"1fr\", \"2fr\", \"1fr\"],\n gridClasses: \"@md:grid-cols-[1fr_2fr_1fr]\",\n },\n} as const satisfies Record<\n string,\n {\n readonly columns: number;\n readonly widths: readonly string[];\n readonly gridClasses: string;\n }\n>;\n\n/**\n * Union type of all section layout types, derived from SECTION_LAYOUT_CONFIG keys.\n * @see deriving-typeof-for-object-keys pattern\n */\nexport type SectionLayoutType = keyof typeof SECTION_LAYOUT_CONFIG;\n\n/** @deprecated Use SECTION_LAYOUT_CONFIG instead */\nexport const sectionLayoutConfig = SECTION_LAYOUT_CONFIG;\n"]}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// src/types/widget-schema.ts
|
|
2
|
+
var WIDGET_TYPE_NAMES = {
|
|
3
|
+
Alert: "AlertWidget",
|
|
4
|
+
Calendar: "CalendarWidget",
|
|
5
|
+
Carousel: "CarouselWidget",
|
|
6
|
+
CatchUp: "CatchUpWidget",
|
|
7
|
+
Chart: "ChartWidget",
|
|
8
|
+
Container: "ContainerWidget",
|
|
9
|
+
Embed: "EmbedWidget",
|
|
10
|
+
Image: "ImageWidget",
|
|
11
|
+
Layout: "LayoutWidget",
|
|
12
|
+
List: "ListWidget",
|
|
13
|
+
MySite: "MySiteWidget",
|
|
14
|
+
Nested: "NestedWidget",
|
|
15
|
+
QuickShare: "QuickShareWidget",
|
|
16
|
+
RecentActivity: "RecentActivityWidget",
|
|
17
|
+
Spacer: "SpacerWidget",
|
|
18
|
+
Table: "TableWidget",
|
|
19
|
+
Text: "TextWidget",
|
|
20
|
+
ToDo: "ToDoWidget",
|
|
21
|
+
Video: "VideoWidget"
|
|
22
|
+
};
|
|
23
|
+
function isWidgetTypeName(type) {
|
|
24
|
+
return Object.values(WIDGET_TYPE_NAMES).includes(type);
|
|
25
|
+
}
|
|
26
|
+
function isWidgetType(widget, typeName) {
|
|
27
|
+
return widget != null && widget.type === typeName;
|
|
28
|
+
}
|
|
29
|
+
function assertNever(value, context) {
|
|
30
|
+
const message = context ? `Unexpected ${context}: ${String(value)}` : `Unexpected value: ${String(value)}`;
|
|
31
|
+
throw new Error(message);
|
|
32
|
+
}
|
|
33
|
+
function assertDefined(value, name) {
|
|
34
|
+
if (value == null) {
|
|
35
|
+
throw new Error(name ? `${name} is required` : "Value is required");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/types/field-types.ts
|
|
40
|
+
var COLOR_OPTIONS = {
|
|
41
|
+
background: "background",
|
|
42
|
+
foreground: "foreground",
|
|
43
|
+
primary: "primary",
|
|
44
|
+
secondary: "secondary",
|
|
45
|
+
accent: "accent",
|
|
46
|
+
muted: "muted",
|
|
47
|
+
destructive: "destructive"
|
|
48
|
+
};
|
|
49
|
+
var FONT_SIZE_OPTIONS = {
|
|
50
|
+
"2xl": "2xl",
|
|
51
|
+
xl: "xl",
|
|
52
|
+
lg: "lg",
|
|
53
|
+
md: "md",
|
|
54
|
+
sm: "sm",
|
|
55
|
+
xs: "xs"
|
|
56
|
+
};
|
|
57
|
+
var BORDER_RADIUS_OPTIONS = {
|
|
58
|
+
none: "none",
|
|
59
|
+
sm: "sm",
|
|
60
|
+
md: "md",
|
|
61
|
+
lg: "lg",
|
|
62
|
+
xl: "xl",
|
|
63
|
+
full: "full"
|
|
64
|
+
};
|
|
65
|
+
var PADDING_VALUES = [0, 2, 4, 6, 8, 10];
|
|
66
|
+
var BUTTON_SIZE_OPTIONS = {
|
|
67
|
+
sm: "sm",
|
|
68
|
+
default: "default",
|
|
69
|
+
lg: "lg",
|
|
70
|
+
xl: "xl"
|
|
71
|
+
};
|
|
72
|
+
var GAP_OPTIONS = {
|
|
73
|
+
none: "none",
|
|
74
|
+
xs: "xs",
|
|
75
|
+
sm: "sm",
|
|
76
|
+
md: "md",
|
|
77
|
+
lg: "lg",
|
|
78
|
+
xl: "xl"
|
|
79
|
+
};
|
|
80
|
+
var VERTICAL_ALIGN_OPTIONS = {
|
|
81
|
+
top: "top",
|
|
82
|
+
center: "center",
|
|
83
|
+
bottom: "bottom"
|
|
84
|
+
};
|
|
85
|
+
var HORIZONTAL_ALIGN_OPTIONS = {
|
|
86
|
+
left: "left",
|
|
87
|
+
center: "center",
|
|
88
|
+
right: "right"
|
|
89
|
+
};
|
|
90
|
+
var BACKGROUND_TYPES = {
|
|
91
|
+
solid: "solid",
|
|
92
|
+
image: "image"
|
|
93
|
+
};
|
|
94
|
+
var SECTION_LAYOUT_CONFIG = {
|
|
95
|
+
"single-column": { columns: 1, widths: ["1fr"], gridClasses: "" },
|
|
96
|
+
"2c-equal": {
|
|
97
|
+
columns: 2,
|
|
98
|
+
widths: ["1fr", "1fr"],
|
|
99
|
+
gridClasses: "@md:grid-cols-2"
|
|
100
|
+
},
|
|
101
|
+
"2c-left-wider": {
|
|
102
|
+
columns: 2,
|
|
103
|
+
widths: ["2fr", "1fr"],
|
|
104
|
+
gridClasses: "@md:grid-cols-[2fr_1fr]"
|
|
105
|
+
},
|
|
106
|
+
"2c-right-wider": {
|
|
107
|
+
columns: 2,
|
|
108
|
+
widths: ["1fr", "2fr"],
|
|
109
|
+
gridClasses: "@md:grid-cols-[1fr_2fr]"
|
|
110
|
+
},
|
|
111
|
+
"2c-left-narrow": {
|
|
112
|
+
columns: 2,
|
|
113
|
+
widths: ["1fr", "3fr"],
|
|
114
|
+
gridClasses: "@md:grid-cols-[1fr_3fr]"
|
|
115
|
+
},
|
|
116
|
+
"2c-right-narrow": {
|
|
117
|
+
columns: 2,
|
|
118
|
+
widths: ["3fr", "1fr"],
|
|
119
|
+
gridClasses: "@md:grid-cols-[3fr_1fr]"
|
|
120
|
+
},
|
|
121
|
+
"3c-equal": {
|
|
122
|
+
columns: 3,
|
|
123
|
+
widths: ["1fr", "1fr", "1fr"],
|
|
124
|
+
gridClasses: "@md:grid-cols-3"
|
|
125
|
+
},
|
|
126
|
+
"3c-middle-wider": {
|
|
127
|
+
columns: 3,
|
|
128
|
+
widths: ["1fr", "2fr", "1fr"],
|
|
129
|
+
gridClasses: "@md:grid-cols-[1fr_2fr_1fr]"
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
var sectionLayoutConfig = SECTION_LAYOUT_CONFIG;
|
|
133
|
+
|
|
134
|
+
export { BACKGROUND_TYPES, BORDER_RADIUS_OPTIONS, BUTTON_SIZE_OPTIONS, COLOR_OPTIONS, FONT_SIZE_OPTIONS, GAP_OPTIONS, HORIZONTAL_ALIGN_OPTIONS, PADDING_VALUES, SECTION_LAYOUT_CONFIG, VERTICAL_ALIGN_OPTIONS, WIDGET_TYPE_NAMES, assertDefined, assertNever, isWidgetType, isWidgetTypeName, sectionLayoutConfig };
|
|
135
|
+
//# sourceMappingURL=chunk-EWR5EIBP.js.map
|
|
136
|
+
//# sourceMappingURL=chunk-EWR5EIBP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/widget-schema.ts","../src/types/field-types.ts"],"names":[],"mappings":";AAOO,IAAM,iBAAA,GAAoB;AAAA,EAC/B,KAAA,EAAO,aAAA;AAAA,EACP,QAAA,EAAU,gBAAA;AAAA,EACV,QAAA,EAAU,gBAAA;AAAA,EACV,OAAA,EAAS,eAAA;AAAA,EACT,KAAA,EAAO,aAAA;AAAA,EACP,SAAA,EAAW,iBAAA;AAAA,EACX,KAAA,EAAO,aAAA;AAAA,EACP,KAAA,EAAO,aAAA;AAAA,EACP,MAAA,EAAQ,cAAA;AAAA,EACR,IAAA,EAAM,YAAA;AAAA,EACN,MAAA,EAAQ,cAAA;AAAA,EACR,MAAA,EAAQ,cAAA;AAAA,EACR,UAAA,EAAY,kBAAA;AAAA,EACZ,cAAA,EAAgB,sBAAA;AAAA,EAChB,MAAA,EAAQ,cA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rB,WAAA,EAAa;AAAA,GACf;AAAA,EACA,eAAA,EAAiB;AAAA,IACf,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,CAAC,KAAA,EAAO,KAAK,CAAA;AAAA,IACrB,WAAA,EAAa;AAAA,GACf;AAAA,EACA,gBAAA,EAAkB;AAAA,IAChB,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,CAAC,KAAA,EAAO,KAAK,CAAA;AAAA,IACrB,WAAA,EAAa;AAAA,GACf;AAAA,EACA,gBAAA,EAAkB;AAAA,IAChB,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,CAAC,KAAA,EAAO,KAAK,CAAA;AAAA,IACrB,WAAA,EAAa;AAAA,GACf;AAAA,EACA,iBAAA,EAAmB;AAAA,IACjB,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,CAAC,KAAA,EAAO,KAAK,CAAA;AAAA,IACrB,WAAA,EAAa;AAAA,GACf;AAAA,EACA,UAAA,EAAY;AAAA,IACV,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,CAAC,KAAA,EAAO,KAAA,EAAO,KAAK,CAAA;AAAA,IAC5B,WAAA,EAAa;AAAA,GACf;AAAA,EACA,iBAAA,EAAmB;AAAA,IACjB,OAAA,EAAS,CAAA;AAAA,IACT,MAAA,EAAQ,CAAC,KAAA,EAAO,KAAA,EAAO,KAAK,CAAA;AAAA,IAC5B,WAAA,EAAa;AAAA;AAEjB;AAgBO,IAAM,mBAAA,GAAsB","file":"chunk-EWR5EIBP.js","sourcesContent":["import type { ComponentType } from \"react\";\n\n/**\n * Widget type names as a const object.\n * This serves as the single source of truth for widget discriminants.\n * Use `as const` for literal type inference (safety-as-const-deep-readonly rule).\n */\nexport const WIDGET_TYPE_NAMES = {\n Alert: \"AlertWidget\",\n Calendar: \"CalendarWidget\",\n Carousel: \"CarouselWidget\",\n CatchUp: \"CatchUpWidget\",\n Chart: \"ChartWidget\",\n Container: \"ContainerWidget\",\n Embed: \"EmbedWidget\",\n Image: \"ImageWidget\",\n Layout: \"LayoutWidget\",\n List: \"ListWidget\",\n MySite: \"MySiteWidget\",\n Nested: \"NestedWidget\",\n QuickShare: \"QuickShareWidget\",\n RecentActivity: \"RecentActivityWidget\",\n Spacer: \"SpacerWidget\",\n Table: \"TableWidget\",\n Text: \"TextWidget\",\n ToDo: \"ToDoWidget\",\n Video: \"VideoWidget\",\n} as const;\n\n/**\n * Union of all known widget type names.\n * Derived from WIDGET_TYPE_NAMES to avoid duplication (deriving-typeof-for-object-keys rule).\n */\nexport type WidgetTypeName =\n (typeof WIDGET_TYPE_NAMES)[keyof typeof WIDGET_TYPE_NAMES];\n\n/**\n * Legacy alias for backwards compatibility.\n * Prefer using WidgetTypeName for new code when you need the union type.\n */\nexport type WidgetType = string;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type WidgetRegistry = Record<WidgetType, ComponentType<any>>;\n\n/**\n * Base widget schema with loose typing for runtime data.\n * Use TypedWidgetSchema<T> when you have a known registry for better type safety.\n */\nexport type WidgetSchema = {\n readonly type: WidgetType;\n readonly props: Readonly<Record<string, unknown>>;\n readonly id?: string; // Optional unique identifier for drag-and-drop\n /** Column index for masonry layouts (0-indexed) */\n readonly columnIndex?: number;\n};\n\n/**\n * Type-safe widget schema based on registry.\n * Uses discriminated unions - the `type` field serves as discriminant.\n * When narrowed (e.g., `if (widget.type === \"AlertWidget\")`),\n * TypeScript automatically knows the correct props type.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type TypedWidgetSchema<T extends Record<string, ComponentType<any>>> = {\n [K in keyof T]: {\n readonly type: K;\n readonly props: Readonly<React.ComponentProps<T[K]>>;\n readonly id?: string;\n /** Column index for masonry layouts (0-indexed) */\n readonly columnIndex?: number;\n };\n}[keyof T];\n\n/**\n * Widget path in the tree - array of indices.\n * Readonly tuple to prevent accidental mutation.\n */\nexport type WidgetPath = readonly number[];\n\n// ============================================================================\n// Type Guards and Assertion Functions\n// ============================================================================\n\n/**\n * Type predicate to check if a string is a known widget type name.\n * Use for runtime validation of widget types.\n *\n * @example\n * if (isWidgetTypeName(widget.type)) {\n * // TypeScript knows widget.type is WidgetTypeName\n * }\n */\nexport function isWidgetTypeName(type: string): type is WidgetTypeName {\n // Type assertion required in type guard: Object.values() returns string[], but we\n // need to check against WidgetTypeName values. The assertion is safe because we're\n // checking membership, and the return type predicate ensures correct narrowing.\n return Object.values(WIDGET_TYPE_NAMES).includes(type as WidgetTypeName);\n}\n\n/**\n * Type predicate to check if a widget has a specific type.\n * Enables type-safe widget narrowing without `as` assertions.\n *\n * @example\n * if (isWidgetType(widget, \"LayoutWidget\")) {\n * // TypeScript knows widget.type === \"LayoutWidget\"\n * // and widget.props is LayoutWidget props\n * }\n */\nexport function isWidgetType<T extends WidgetTypeName>(\n widget: WidgetSchema | null | undefined,\n typeName: T,\n): widget is WidgetSchema & { readonly type: T } {\n return widget != null && widget.type === typeName;\n}\n\n/**\n * Helper for exhaustive switch statements on widget types.\n * Use in the default case to ensure all widget types are handled.\n *\n * @example\n * switch (widget.type) {\n * case \"AlertWidget\": return handleAlert();\n * case \"TextWidget\": return handleText();\n * // ... all other widget types\n * default: return assertNever(widget.type, \"widget type\");\n * }\n */\nexport function assertNever(value: never, context?: string): never {\n const message = context\n ? `Unexpected ${context}: ${String(value)}`\n : `Unexpected value: ${String(value)}`;\n throw new Error(message);\n}\n\n/**\n * Assertion function that throws if value is undefined.\n * Narrows the type to exclude undefined.\n *\n * @example\n * const widget = screen[0];\n * assertDefined(widget, \"widget at index 0\");\n * // TypeScript knows widget is defined here\n */\nexport function assertDefined<T>(\n value: T | undefined | null,\n name?: string,\n): asserts value is T {\n if (value == null) {\n throw new Error(name ? `${name} is required` : \"Value is required\");\n }\n}\n","import type { ShareableItem } from \"./shareable-item\";\n\n// ============================================================================\n// Color Options - Derive type from constant for single source of truth\n// ============================================================================\n\n/**\n * Color options constant - single source of truth for color values.\n * Use COLOR_OPTIONS.primary instead of \"primary\" for type-safe comparisons.\n */\nexport const COLOR_OPTIONS = {\n background: \"background\",\n foreground: \"foreground\",\n primary: \"primary\",\n secondary: \"secondary\",\n accent: \"accent\",\n muted: \"muted\",\n destructive: \"destructive\",\n} as const;\n\n/**\n * Union type of all color options, derived from COLOR_OPTIONS constant.\n * @see deriving-typeof-for-object-keys pattern\n */\nexport type ColorOptions = (typeof COLOR_OPTIONS)[keyof typeof COLOR_OPTIONS];\n\n// ============================================================================\n// Size Options - Derive types from constants for single source of truth\n// ============================================================================\n\nexport const FONT_SIZE_OPTIONS = {\n \"2xl\": \"2xl\",\n xl: \"xl\",\n lg: \"lg\",\n md: \"md\",\n sm: \"sm\",\n xs: \"xs\",\n} as const;\n\nexport type FontSizeOptions =\n (typeof FONT_SIZE_OPTIONS)[keyof typeof FONT_SIZE_OPTIONS];\n\nexport const BORDER_RADIUS_OPTIONS = {\n none: \"none\",\n sm: \"sm\",\n md: \"md\",\n lg: \"lg\",\n xl: \"xl\",\n full: \"full\",\n} as const;\n\nexport type BorderRadiusOptions =\n (typeof BORDER_RADIUS_OPTIONS)[keyof typeof BORDER_RADIUS_OPTIONS];\n\n/** Padding values - numeric, so we use a tuple for derivation */\nexport const PADDING_VALUES = [0, 2, 4, 6, 8, 10] as const;\nexport type PaddingOptions = (typeof PADDING_VALUES)[number];\n\nexport const BUTTON_SIZE_OPTIONS = {\n sm: \"sm\",\n default: \"default\",\n lg: \"lg\",\n xl: \"xl\",\n} as const;\n\nexport type ButtonSizeOptions =\n (typeof BUTTON_SIZE_OPTIONS)[keyof typeof BUTTON_SIZE_OPTIONS];\n\nexport const GAP_OPTIONS = {\n none: \"none\",\n xs: \"xs\",\n sm: \"sm\",\n md: \"md\",\n lg: \"lg\",\n xl: \"xl\",\n} as const;\n\nexport type GapOptions = (typeof GAP_OPTIONS)[keyof typeof GAP_OPTIONS];\n\n// ============================================================================\n// Alignment Options - Derive from constants\n// ============================================================================\n\nexport const VERTICAL_ALIGN_OPTIONS = {\n top: \"top\",\n center: \"center\",\n bottom: \"bottom\",\n} as const;\n\nexport type VerticalAlign =\n (typeof VERTICAL_ALIGN_OPTIONS)[keyof typeof VERTICAL_ALIGN_OPTIONS];\n\nexport const HORIZONTAL_ALIGN_OPTIONS = {\n left: \"left\",\n center: \"center\",\n right: \"right\",\n} as const;\n\nexport type HorizontalAlign =\n (typeof HORIZONTAL_ALIGN_OPTIONS)[keyof typeof HORIZONTAL_ALIGN_OPTIONS];\n\nexport type AlignOptions = {\n vertical?: VerticalAlign;\n horizontal?: HorizontalAlign;\n};\n\n// ============================================================================\n// Background Options - Derive from constant\n// ============================================================================\n\nexport const BACKGROUND_TYPES = {\n solid: \"solid\",\n image: \"image\",\n} as const;\n\nexport type BackgroundType =\n (typeof BACKGROUND_TYPES)[keyof typeof BACKGROUND_TYPES];\nexport interface BackgroundValue {\n type: BackgroundType;\n color?: ColorOptions;\n resource?: ShareableItem;\n}\n\n// ============================================================================\n// Section Layout - Derive type from config keys (single source of truth)\n// ============================================================================\n\n/**\n * Section layout configuration - single source of truth for layout types.\n * SectionLayoutType is derived from these keys to prevent drift.\n */\nexport const SECTION_LAYOUT_CONFIG = {\n \"single-column\": { columns: 1, widths: [\"1fr\"], gridClasses: \"\" },\n \"2c-equal\": {\n columns: 2,\n widths: [\"1fr\", \"1fr\"],\n gridClasses: \"@md:grid-cols-2\",\n },\n \"2c-left-wider\": {\n columns: 2,\n widths: [\"2fr\", \"1fr\"],\n gridClasses: \"@md:grid-cols-[2fr_1fr]\",\n },\n \"2c-right-wider\": {\n columns: 2,\n widths: [\"1fr\", \"2fr\"],\n gridClasses: \"@md:grid-cols-[1fr_2fr]\",\n },\n \"2c-left-narrow\": {\n columns: 2,\n widths: [\"1fr\", \"3fr\"],\n gridClasses: \"@md:grid-cols-[1fr_3fr]\",\n },\n \"2c-right-narrow\": {\n columns: 2,\n widths: [\"3fr\", \"1fr\"],\n gridClasses: \"@md:grid-cols-[3fr_1fr]\",\n },\n \"3c-equal\": {\n columns: 3,\n widths: [\"1fr\", \"1fr\", \"1fr\"],\n gridClasses: \"@md:grid-cols-3\",\n },\n \"3c-middle-wider\": {\n columns: 3,\n widths: [\"1fr\", \"2fr\", \"1fr\"],\n gridClasses: \"@md:grid-cols-[1fr_2fr_1fr]\",\n },\n} as const satisfies Record<\n string,\n {\n readonly columns: number;\n readonly widths: readonly string[];\n readonly gridClasses: string;\n }\n>;\n\n/**\n * Union type of all section layout types, derived from SECTION_LAYOUT_CONFIG keys.\n * @see deriving-typeof-for-object-keys pattern\n */\nexport type SectionLayoutType = keyof typeof SECTION_LAYOUT_CONFIG;\n\n/** @deprecated Use SECTION_LAYOUT_CONFIG instead */\nexport const sectionLayoutConfig = SECTION_LAYOUT_CONFIG;\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
|
|
6
|
+
// src/data-sources/context.tsx
|
|
7
|
+
var DataSourceContext = react.createContext({});
|
|
8
|
+
function DataSourceProvider({
|
|
9
|
+
baseUrl,
|
|
10
|
+
getApiHeaders,
|
|
11
|
+
children
|
|
12
|
+
}) {
|
|
13
|
+
const value = react.useMemo(
|
|
14
|
+
() => ({ baseUrl, getApiHeaders }),
|
|
15
|
+
[baseUrl, getApiHeaders]
|
|
16
|
+
);
|
|
17
|
+
return /* @__PURE__ */ jsxRuntime.jsx(DataSourceContext.Provider, { value, children });
|
|
18
|
+
}
|
|
19
|
+
function useDataSourceConfig() {
|
|
20
|
+
return react.useContext(DataSourceContext);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.DataSourceProvider = DataSourceProvider;
|
|
24
|
+
exports.useDataSourceConfig = useDataSourceConfig;
|
|
25
|
+
//# sourceMappingURL=context.cjs.map
|
|
26
|
+
//# sourceMappingURL=context.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/data-sources/context.tsx"],"names":["createContext","useMemo","jsx","useContext"],"mappings":";;;;;;AAOA,IAAM,iBAAA,GAAoBA,mBAAA,CAAsC,EAAE,CAAA;AAQ3D,SAAS,kBAAA,CAAmB;AAAA,EACjC,OAAA;AAAA,EACA,aAAA;AAAA,EACA;AACF,CAAA,EAA4B;AAC1B,EAAA,MAAM,KAAA,GAAQC,aAAA;AAAA,IACZ,OAAO,EAAE,OAAA,EAAS,aAAA,EAAc,CAAA;AAAA,IAChC,CAAC,SAAS,aAAa;AAAA,GACzB;AAEA,EAAA,uBACEC,cAAA,CAAC,iBAAA,CAAkB,QAAA,EAAlB,EAA2B,OACzB,QAAA,EACH,CAAA;AAEJ;AAEO,SAAS,mBAAA,GAA8C;AAC5D,EAAA,OAAOC,iBAAW,iBAAiB,CAAA;AACrC","file":"context.cjs","sourcesContent":["import { createContext, useContext, useMemo, type ReactNode } from \"react\";\n\nexport interface DataSourceContextValue {\n baseUrl?: string | undefined;\n getApiHeaders?: (() => Record<string, string>) | undefined;\n}\n\nconst DataSourceContext = createContext<DataSourceContextValue>({});\n\nexport interface DataSourceProviderProps {\n baseUrl?: string;\n getApiHeaders?: () => Record<string, string>;\n children: ReactNode;\n}\n\nexport function DataSourceProvider({\n baseUrl,\n getApiHeaders,\n children,\n}: DataSourceProviderProps) {\n const value = useMemo(\n () => ({ baseUrl, getApiHeaders }),\n [baseUrl, getApiHeaders],\n );\n\n return (\n <DataSourceContext.Provider value={value}>\n {children}\n </DataSourceContext.Provider>\n );\n}\n\nexport function useDataSourceConfig(): DataSourceContextValue {\n return useContext(DataSourceContext);\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
interface DataSourceContextValue {
|
|
5
|
+
baseUrl?: string | undefined;
|
|
6
|
+
getApiHeaders?: (() => Record<string, string>) | undefined;
|
|
7
|
+
}
|
|
8
|
+
interface DataSourceProviderProps {
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
getApiHeaders?: () => Record<string, string>;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
declare function DataSourceProvider({ baseUrl, getApiHeaders, children, }: DataSourceProviderProps): react_jsx_runtime.JSX.Element;
|
|
14
|
+
declare function useDataSourceConfig(): DataSourceContextValue;
|
|
15
|
+
|
|
16
|
+
export { type DataSourceContextValue, DataSourceProvider, type DataSourceProviderProps, useDataSourceConfig };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
interface DataSourceContextValue {
|
|
5
|
+
baseUrl?: string | undefined;
|
|
6
|
+
getApiHeaders?: (() => Record<string, string>) | undefined;
|
|
7
|
+
}
|
|
8
|
+
interface DataSourceProviderProps {
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
getApiHeaders?: () => Record<string, string>;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
declare function DataSourceProvider({ baseUrl, getApiHeaders, children, }: DataSourceProviderProps): react_jsx_runtime.JSX.Element;
|
|
14
|
+
declare function useDataSourceConfig(): DataSourceContextValue;
|
|
15
|
+
|
|
16
|
+
export { type DataSourceContextValue, DataSourceProvider, type DataSourceProviderProps, useDataSourceConfig };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createContext, useMemo, useContext } from 'react';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
// src/data-sources/context.tsx
|
|
5
|
+
var DataSourceContext = createContext({});
|
|
6
|
+
function DataSourceProvider({
|
|
7
|
+
baseUrl,
|
|
8
|
+
getApiHeaders,
|
|
9
|
+
children
|
|
10
|
+
}) {
|
|
11
|
+
const value = useMemo(
|
|
12
|
+
() => ({ baseUrl, getApiHeaders }),
|
|
13
|
+
[baseUrl, getApiHeaders]
|
|
14
|
+
);
|
|
15
|
+
return /* @__PURE__ */ jsx(DataSourceContext.Provider, { value, children });
|
|
16
|
+
}
|
|
17
|
+
function useDataSourceConfig() {
|
|
18
|
+
return useContext(DataSourceContext);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { DataSourceProvider, useDataSourceConfig };
|
|
22
|
+
//# sourceMappingURL=context.js.map
|
|
23
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/data-sources/context.tsx"],"names":[],"mappings":";;;;AAOA,IAAM,iBAAA,GAAoB,aAAA,CAAsC,EAAE,CAAA;AAQ3D,SAAS,kBAAA,CAAmB;AAAA,EACjC,OAAA;AAAA,EACA,aAAA;AAAA,EACA;AACF,CAAA,EAA4B;AAC1B,EAAA,MAAM,KAAA,GAAQ,OAAA;AAAA,IACZ,OAAO,EAAE,OAAA,EAAS,aAAA,EAAc,CAAA;AAAA,IAChC,CAAC,SAAS,aAAa;AAAA,GACzB;AAEA,EAAA,uBACE,GAAA,CAAC,iBAAA,CAAkB,QAAA,EAAlB,EAA2B,OACzB,QAAA,EACH,CAAA;AAEJ;AAEO,SAAS,mBAAA,GAA8C;AAC5D,EAAA,OAAO,WAAW,iBAAiB,CAAA;AACrC","file":"context.js","sourcesContent":["import { createContext, useContext, useMemo, type ReactNode } from \"react\";\n\nexport interface DataSourceContextValue {\n baseUrl?: string | undefined;\n getApiHeaders?: (() => Record<string, string>) | undefined;\n}\n\nconst DataSourceContext = createContext<DataSourceContextValue>({});\n\nexport interface DataSourceProviderProps {\n baseUrl?: string;\n getApiHeaders?: () => Record<string, string>;\n children: ReactNode;\n}\n\nexport function DataSourceProvider({\n baseUrl,\n getApiHeaders,\n children,\n}: DataSourceProviderProps) {\n const value = useMemo(\n () => ({ baseUrl, getApiHeaders }),\n [baseUrl, getApiHeaders],\n );\n\n return (\n <DataSourceContext.Provider value={value}>\n {children}\n </DataSourceContext.Provider>\n );\n}\n\nexport function useDataSourceConfig(): DataSourceContextValue {\n return useContext(DataSourceContext);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"types.cjs"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
type DataSourceType = "api" | "custom" | "static";
|
|
2
|
+
type StaticSourceType = "collections" | "categories" | "tags";
|
|
3
|
+
type ShareableType = "Medium" | "Page" | "EnrollmentPack" | "Library" | "Product";
|
|
4
|
+
interface SelectedItem {
|
|
5
|
+
/** The unique ID of the selected item */
|
|
6
|
+
id: string | number;
|
|
7
|
+
/** The type of shareable content */
|
|
8
|
+
shareableType: ShareableType;
|
|
9
|
+
/** Optional cached data for preview/display purposes in the editor UI */
|
|
10
|
+
cachedData?: {
|
|
11
|
+
title?: string;
|
|
12
|
+
imageUrl?: string;
|
|
13
|
+
kind?: string;
|
|
14
|
+
};
|
|
15
|
+
/** Widget-specific per-item configuration overrides */
|
|
16
|
+
widgetConfig?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
interface ApiDataSource {
|
|
19
|
+
type: "api";
|
|
20
|
+
/** API endpoint URL (can include {variable} placeholders, e.g., /api/reps/{rep_id}/items) */
|
|
21
|
+
endpoint: string;
|
|
22
|
+
/** HTTP method (defaults to GET) */
|
|
23
|
+
method?: "GET" | "POST" | "PUT" | "DELETE";
|
|
24
|
+
/** Request headers */
|
|
25
|
+
headers?: Record<string, string>;
|
|
26
|
+
/** Request body for POST/PUT (will be JSON.stringify'd) */
|
|
27
|
+
body?: unknown;
|
|
28
|
+
/**
|
|
29
|
+
* Path to extract from response using dot notation
|
|
30
|
+
* e.g., "data.items" extracts response.data.items
|
|
31
|
+
*/
|
|
32
|
+
resultPath?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Which widget props this source populates
|
|
35
|
+
* e.g., ['data'] means the fetched result goes to props.data
|
|
36
|
+
*/
|
|
37
|
+
targetProps: string[];
|
|
38
|
+
/**
|
|
39
|
+
* Name of a registered transform function to process the data
|
|
40
|
+
* Transform is applied after resultPath extraction
|
|
41
|
+
*/
|
|
42
|
+
transform?: string;
|
|
43
|
+
/** Per-source variables for endpoint template interpolation (e.g., { limit: "10" }) */
|
|
44
|
+
variables?: Record<string, string>;
|
|
45
|
+
/**
|
|
46
|
+
* Auto-refresh interval in milliseconds
|
|
47
|
+
* 0 or undefined = no auto-refresh
|
|
48
|
+
*/
|
|
49
|
+
refreshInterval?: number;
|
|
50
|
+
}
|
|
51
|
+
interface CustomDataSource {
|
|
52
|
+
type: "custom";
|
|
53
|
+
/** Array of selected items to fetch */
|
|
54
|
+
selectedItems: SelectedItem[];
|
|
55
|
+
/**
|
|
56
|
+
* Which widget props this source populates
|
|
57
|
+
* e.g., ['slides'] means the fetched results go to props.slides
|
|
58
|
+
*/
|
|
59
|
+
targetProps: string[];
|
|
60
|
+
/**
|
|
61
|
+
* Name of a registered transform function to process the data
|
|
62
|
+
* Transform is applied after all items are fetched
|
|
63
|
+
*/
|
|
64
|
+
transform?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Auto-refresh interval in milliseconds
|
|
67
|
+
* 0 or undefined = no auto-refresh
|
|
68
|
+
*/
|
|
69
|
+
refreshInterval?: number;
|
|
70
|
+
}
|
|
71
|
+
interface StaticDataSource {
|
|
72
|
+
type: "static";
|
|
73
|
+
/** The type of static data (collections, categories, tags) */
|
|
74
|
+
staticType: StaticSourceType;
|
|
75
|
+
/** The selected item ID */
|
|
76
|
+
selectedId: string | number;
|
|
77
|
+
/** Cached data for preview/display in editor UI */
|
|
78
|
+
cachedData?: {
|
|
79
|
+
title?: string;
|
|
80
|
+
imageUrl?: string;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Which widget props this source populates
|
|
84
|
+
*/
|
|
85
|
+
targetProps: string[];
|
|
86
|
+
/**
|
|
87
|
+
* Name of a registered transform function to process the data
|
|
88
|
+
*/
|
|
89
|
+
transform?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Auto-refresh interval in milliseconds
|
|
92
|
+
* 0 or undefined = no auto-refresh
|
|
93
|
+
*/
|
|
94
|
+
refreshInterval?: number;
|
|
95
|
+
}
|
|
96
|
+
type DataSource = ApiDataSource | CustomDataSource | StaticDataSource;
|
|
97
|
+
interface DataSourceConfig {
|
|
98
|
+
/** Array of data sources (usually just one, but supports multiple) */
|
|
99
|
+
sources: DataSource[];
|
|
100
|
+
/** Loading state configuration */
|
|
101
|
+
loading?: {
|
|
102
|
+
/** Show skeleton placeholder while loading (default: true) */
|
|
103
|
+
showSkeleton?: boolean;
|
|
104
|
+
};
|
|
105
|
+
/** Error handling configuration */
|
|
106
|
+
error?: {
|
|
107
|
+
/** Fallback props to use when fetch fails */
|
|
108
|
+
fallback?: Record<string, unknown>;
|
|
109
|
+
/** Number of retry attempts (default: 0) */
|
|
110
|
+
retryCount?: number;
|
|
111
|
+
/** Delay between retries in ms (default: 1000) */
|
|
112
|
+
retryDelay?: number;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** Item returned by static data fetchers */
|
|
116
|
+
interface StaticItem {
|
|
117
|
+
id: string | number;
|
|
118
|
+
title: string;
|
|
119
|
+
imageUrl?: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export type { ApiDataSource, CustomDataSource, DataSource, DataSourceConfig, DataSourceType, SelectedItem, ShareableType, StaticDataSource, StaticItem, StaticSourceType };
|