andesine 0.0.1-alpha.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.
@@ -0,0 +1,351 @@
1
+ import { C as Client } from './shared/andesine.bcb7a57d.js';
2
+ import { a as ContentPieceWithAdditionalData, J as JSONContent } from './shared/andesine.5e4b2db8.js';
3
+
4
+ type ContextValue = string | number | boolean | undefined | null | ContextObject | ContextArray;
5
+ type ContextObject = {
6
+ [x: string]: ContextValue;
7
+ };
8
+ type ContextArray = Array<ContextValue>;
9
+ type IsFunction<T, R, Fallback = T> = T extends (...args: any[]) => any ? R : Fallback;
10
+ type IsObject<T, R, Fallback = T> = IsFunction<T, Fallback, T extends object ? (T extends any[] ? Fallback : R) : Fallback>;
11
+ type Tail<S> = S extends `${string}.${infer T}` ? Tail<T> : S;
12
+ type Value<T> = T[keyof T];
13
+ type FlattenStepOne<T> = {
14
+ [K in keyof T as K extends string ? IsObject<T[K], `${K}.${keyof T[K] & string}`, K> : K]: IsObject<T[K], {
15
+ [key in keyof T[K]]: T[K][key];
16
+ }>;
17
+ };
18
+ type FlattenStepTwo<T> = {
19
+ [a in keyof T]: IsObject<T[a], Value<{
20
+ [M in keyof T[a] as M extends Tail<a> ? M : never]: T[a][M];
21
+ }>>;
22
+ };
23
+ type FlattenOneLevel<T> = FlattenStepTwo<FlattenStepOne<T>>;
24
+ type Flatten<T> = T extends FlattenOneLevel<T> ? T : Flatten<FlattenOneLevel<T>>;
25
+ type UsableEnv<R extends ContextObject = ContextObject, W extends ContextObject = ContextObject> = {
26
+ readable: R;
27
+ writable: W;
28
+ };
29
+ type ExtensionContentType = "paragraph" | "heading" | "blockquote" | "element" | "image" | "codeBlock" | "embed" | "bulletList" | "orderedList" | "taskList" | "horizontalRule" | "table" | "block";
30
+ type UseEnv<C extends ExtensionBaseContext> = C[typeof __usableEnv] extends UsableEnv ? <K extends keyof Flatten<C[typeof __usableEnv]["readable"]> | keyof Flatten<C[typeof __usableEnv]["writable"]> | keyof C[typeof __usableEnv]["readable"] | keyof C[typeof __usableEnv]["writable"]>(key: K) => K extends keyof Flatten<C[typeof __usableEnv]["readable"]> ? Val<Flatten<C[typeof __usableEnv]["readable"]>[K]> : K extends keyof Flatten<C[typeof __usableEnv]["writable"]> ? [
31
+ MutableVal<Flatten<C[typeof __usableEnv]["writable"]>[K]>,
32
+ (value: Flatten<C[typeof __usableEnv]["writable"]>[K]) => void
33
+ ] : K extends keyof C[typeof __usableEnv]["readable"] ? Val<C[typeof __usableEnv]["readable"][K]> : K extends keyof C[typeof __usableEnv]["writable"] ? [
34
+ MutableVal<C[typeof __usableEnv]["writable"][K]>,
35
+ (value: C[typeof __usableEnv]["writable"][K]) => void
36
+ ] : never : never;
37
+ interface ExtensionBaseContext<C extends ContextObject = ContextObject> {
38
+ client: Omit<Client, "reconfigure">;
39
+ token: string;
40
+ extensionId: string;
41
+ config?: C;
42
+ spec: ExtensionSpec;
43
+ [__usableEnv]: UsableEnv<any, any>;
44
+ use: UseEnv<this>;
45
+ flush(): Promise<void>;
46
+ notify(message: {
47
+ text: string;
48
+ type: "success" | "error";
49
+ }): Promise<void>;
50
+ }
51
+ interface ExtensionBaseViewContext<C extends ContextObject = ContextObject> extends ExtensionBaseContext<C> {
52
+ css(strings: TemplateStringsArray, ...values: Array<ContextValue>): string;
53
+ }
54
+ interface ExtensionConfigurationViewContext<C extends ContextObject = ContextObject> extends ExtensionBaseViewContext<C> {
55
+ [__usableEnv]: UsableEnv<{
56
+ [__value]: any;
57
+ }, {
58
+ config: C;
59
+ }>;
60
+ }
61
+ interface ExtensionContentPieceViewContext<C extends ContextObject = ContextObject, D extends ContextObject = ContextObject> extends ExtensionBaseViewContext<C> {
62
+ [__usableEnv]: UsableEnv<{
63
+ contentPiece: ContentPieceWithAdditionalData;
64
+ }, {
65
+ data: D;
66
+ }>;
67
+ }
68
+ interface ExtensionBlockActionViewContext<C extends ContextObject = ContextObject> extends ExtensionBaseViewContext<C> {
69
+ [__usableEnv]: UsableEnv<{
70
+ content: JSONContent;
71
+ }, {
72
+ [__value]: any;
73
+ }>;
74
+ replaceContent(contentHTML: string): Promise<void>;
75
+ refreshContent(): Promise<void>;
76
+ }
77
+ interface ExtensionElementViewContext<C extends ContextObject = ContextObject, P extends Record<string, any> = Record<string, any>> extends ExtensionBaseViewContext<C> {
78
+ [__usableEnv]: UsableEnv<{
79
+ [__value]: any;
80
+ }, {
81
+ props: P;
82
+ }>;
83
+ }
84
+ declare const __brand: unique symbol;
85
+ declare const __props: unique symbol;
86
+ declare const __mutable: unique symbol;
87
+ declare const __usableEnv: unique symbol;
88
+ declare const __value: unique symbol;
89
+ declare const __id: unique symbol;
90
+ declare const __componentName: unique symbol;
91
+ type Brand<B> = {
92
+ [__brand]: B;
93
+ };
94
+ type Val<V extends ContextValue | {
95
+ [K: string]: Val;
96
+ } = ContextValue | {
97
+ [K: string]: Val;
98
+ }> = Brand<"Val"> & {
99
+ (): V;
100
+ [__value]: V;
101
+ [__id]: string;
102
+ };
103
+ type MutableVal<V extends ContextValue | {
104
+ [K: string]: MutableVal;
105
+ } = ContextValue | {
106
+ [K: string]: MutableVal;
107
+ }> = Val<V> & {
108
+ [__mutable]: true;
109
+ };
110
+ type Func<C extends ExtensionBaseContext | never = never> = Brand<"Func"> & {
111
+ (context: C): void | Promise<void>;
112
+ [__id]: string;
113
+ };
114
+ interface ExtensionEnvironment {
115
+ data: Record<string, Val>;
116
+ func: Record<string, Func<any>>;
117
+ views: Record<string, View<any>>;
118
+ effects: Array<{
119
+ [__id]: string;
120
+ dependencies: string[];
121
+ run: () => void;
122
+ }>;
123
+ currentScope: {
124
+ func: string[];
125
+ temp: string[];
126
+ effects: string[];
127
+ uid: string;
128
+ } | null;
129
+ }
130
+ interface ExtensionMetadata {
131
+ __value: typeof __value;
132
+ __id: typeof __id;
133
+ __componentName: typeof __componentName;
134
+ __usableEnv: typeof __usableEnv;
135
+ }
136
+ type View<C extends Partial<ExtensionBaseViewContext> | never = never> = Brand<"View"> & {
137
+ [__value]: (context: C) => ExtensionElement | Promise<ExtensionElement>;
138
+ [__id]: string;
139
+ };
140
+ interface ExtensionSpec {
141
+ name: string;
142
+ description: string;
143
+ displayName: string;
144
+ permissions: string[];
145
+ runtime: string;
146
+ icon: string;
147
+ iconDark?: string;
148
+ }
149
+ interface ExtensionBlockActionSpec {
150
+ id: string;
151
+ label: string;
152
+ blocks: string[];
153
+ view: string;
154
+ }
155
+ interface ExtensionPageSpec {
156
+ mainView?: string;
157
+ sidePanelView?: string;
158
+ }
159
+ interface ExtensionElementSpec {
160
+ type: string;
161
+ view: string;
162
+ }
163
+ interface ExtensionRuntimeSpec {
164
+ onUninstall?: string;
165
+ onConfigure?: string;
166
+ configurationView?: string;
167
+ contentPieceView?: string;
168
+ blockActions?: ExtensionBlockActionSpec[];
169
+ page?: ExtensionPageSpec;
170
+ elements?: ExtensionElementSpec[];
171
+ }
172
+ interface Extension {
173
+ getMetadata: () => ExtensionMetadata;
174
+ getEnvironment: () => ExtensionEnvironment;
175
+ triggerEffects: (...dependencies: string[]) => Promise<void>;
176
+ generateRuntimeSpec: () => ExtensionRuntimeSpec;
177
+ generateView: <C extends ExtensionBaseViewContext>(id: string, context: C, uid: string) => Promise<ExtensionElement>;
178
+ removeScope: (id: string) => void;
179
+ runFunction: <C extends ExtensionBaseContext | never = never>(id: string, context: C, uid: string) => Promise<void>;
180
+ }
181
+ type BaseProps<P extends Record<string, any>> = {
182
+ [K in keyof P as Exclude<K, symbol>]?: P[K];
183
+ };
184
+ type BindableProps<P extends Record<string, any>, M extends string | never = never> = {
185
+ [K in keyof P as `bind:${Exclude<Exclude<K, symbol>, M>}`]?: Val<P[K]>;
186
+ } & {
187
+ [K in keyof P as `bind:${Extract<Exclude<K, symbol>, M>}`]?: MutableVal<P[K]>;
188
+ };
189
+ type EventProps<E extends string | never> = {
190
+ [K in E as `on:${Exclude<K, symbol>}`]?: Func;
191
+ };
192
+ interface ExtensionBaseComponent<P extends Record<string, any> = Record<string, any>, E extends string | never = never, M extends string | never = never> {
193
+ (props: BaseProps<P> & BindableProps<P, M> & EventProps<E>): void;
194
+ [__componentName]: string;
195
+ [__props]: P;
196
+ }
197
+ interface ExtensionBaseComponents {
198
+ Content: ExtensionBaseComponent<{
199
+ allowed?: ExtensionContentType[];
200
+ initial?: string;
201
+ class?: string;
202
+ wrapperClass?: string;
203
+ }>;
204
+ Element: ExtensionBaseComponent<{
205
+ type: string;
206
+ }>;
207
+ View: ExtensionBaseComponent<{
208
+ class: string;
209
+ }>;
210
+ SidePanelHeader: ExtensionBaseComponent<{
211
+ defaultSection: string;
212
+ section: string;
213
+ sections: Array<{
214
+ label: string;
215
+ icon?: string;
216
+ id: string;
217
+ action?: ExtensionElement;
218
+ }>;
219
+ }, "back">;
220
+ SidePanelContent: ExtensionBaseComponent<{}>;
221
+ Field: ExtensionBaseComponent<{
222
+ type: string;
223
+ color: "base" | "contrast";
224
+ label: string;
225
+ textarea: boolean;
226
+ value?: string | boolean;
227
+ disabled: boolean;
228
+ placeholder: string;
229
+ optional: boolean;
230
+ options?: Array<{
231
+ label: string;
232
+ value: string;
233
+ }>;
234
+ }, "change", "value">;
235
+ Select: ExtensionBaseComponent<{
236
+ options: Array<{
237
+ label: string;
238
+ value: string;
239
+ }>;
240
+ value?: string;
241
+ class?: string;
242
+ placeholder?: string;
243
+ color?: "base" | "contrast";
244
+ wrapperClass?: string;
245
+ }, "change", "value">;
246
+ Tooltip: ExtensionBaseComponent<{
247
+ text: string;
248
+ class: string;
249
+ fixed: boolean;
250
+ side?: "top" | "bottom" | "left" | "right";
251
+ }>;
252
+ Button: ExtensionBaseComponent<{
253
+ color: "base" | "contrast" | "primary" | "danger" | "success";
254
+ text: "base" | "contrast" | "primary" | "soft" | "danger" | "success";
255
+ class: string;
256
+ loading: boolean;
257
+ disabled: boolean;
258
+ hover: boolean;
259
+ badge: boolean;
260
+ variant: "text" | "solid";
261
+ size: "small" | "medium" | "large";
262
+ target: string;
263
+ link: string;
264
+ }, "click">;
265
+ Card: ExtensionBaseComponent<{
266
+ color: "base" | "contrast" | "primary";
267
+ class: string;
268
+ }>;
269
+ Icon: ExtensionBaseComponent<{
270
+ path: string;
271
+ class: string;
272
+ }>;
273
+ IconButton: ExtensionBaseComponent<{
274
+ color: "base" | "contrast" | "primary";
275
+ text: "base" | "contrast" | "primary" | "soft";
276
+ path: string;
277
+ class: string;
278
+ loading: boolean;
279
+ disabled: boolean;
280
+ }, "click">;
281
+ CollapsibleSection: ExtensionBaseComponent<{
282
+ icon: string;
283
+ label: string;
284
+ action?: ExtensionElement;
285
+ color?: "base" | "primary";
286
+ defaultOpened?: boolean;
287
+ }>;
288
+ Switch: ExtensionBaseComponent<{}>;
289
+ Match: ExtensionBaseComponent<{
290
+ when?: ContextValue;
291
+ }>;
292
+ Show: ExtensionBaseComponent<{
293
+ when: ContextValue;
294
+ }>;
295
+ Text: ExtensionBaseComponent<{
296
+ content: ContextValue;
297
+ }>;
298
+ }
299
+ type ExtensionElement = {
300
+ slot: Array<ExtensionElement | string>;
301
+ component: string;
302
+ props?: Record<string, string | boolean | number>;
303
+ };
304
+ interface ExtensionRuntimeConfig<C extends ContextObject = ContextObject> {
305
+ onUninstall?: Func<ExtensionBaseContext<C>>;
306
+ onConfigure?: Func<ExtensionBaseContext<C>>;
307
+ configurationView?: View<ExtensionConfigurationViewContext<C>>;
308
+ contentPieceView?: View<ExtensionContentPieceViewContext<C>>;
309
+ blockActions?: Array<Omit<ExtensionBlockActionSpec, "view"> & {
310
+ view: View<ExtensionBlockActionViewContext<C>>;
311
+ }>;
312
+ elements?: Array<Omit<ExtensionElementSpec, "view"> & {
313
+ view: View<ExtensionElementViewContext<C, any>>;
314
+ }>;
315
+ page?: {
316
+ mainView?: View<ExtensionBaseViewContext<C>>;
317
+ sidePanelView?: View<ExtensionBaseViewContext<C>>;
318
+ };
319
+ }
320
+ declare const generateId: () => string;
321
+ declare const isVal: <T extends ContextValue>(value: T | Val<T>) => value is Val<T>;
322
+ declare const Components: ExtensionBaseComponents;
323
+ declare function createTemp<T extends ContextValue>(initialValue: T): [MutableVal<T>, (value: T) => void];
324
+ declare function createTemp<T extends ContextValue>(initialValue?: T): [MutableVal<T | undefined>, (value: T | undefined) => void];
325
+ declare function effect<D extends Val[]>(run: () => void, dependencies: D, options?: {
326
+ initial?: boolean;
327
+ }): void;
328
+ declare const computed: (<O extends ContextValue>(compute: () => O, dependencies: Val[]) => Val<O>) & {
329
+ eq: (...values: Array<Val<ContextValue> | ContextValue>) => Val<boolean>;
330
+ neq: (...values: Array<Val<ContextValue> | ContextValue>) => Val<boolean>;
331
+ gt: (a: number | Val<number>, b: number | Val<number>) => Val<boolean>;
332
+ lt: (a: number | Val<number>, b: number | Val<number>) => Val<boolean>;
333
+ and: (...values: Array<Val<ContextValue> | ContextValue>) => Val<boolean>;
334
+ or: (...values: Array<Val<ContextValue> | ContextValue>) => Val<boolean>;
335
+ not: (value: Val<ContextValue> | ContextValue) => Val<boolean>;
336
+ add: (...values: Array<Val<number> | number>) => Val<number>;
337
+ join: (...values: Array<Val<string> | string>) => Val<string>;
338
+ sub: (...values: Val<number>[]) => Val<number>;
339
+ mul: (...values: Val<number>[]) => Val<number>;
340
+ div: (a: number | Val<number>, b: number | Val<number>) => Val<number>;
341
+ mod: (a: number | Val<number>, b: number | Val<number>) => Val<number>;
342
+ neg: (value: number | Val<number>) => Val<number>;
343
+ when: <T extends ContextValue, F extends ContextValue = undefined>(condition: ContextValue | Val<ContextValue>, ifTrue: T | Val<T>, ifFalse?: F | Val<F>) => F extends undefined ? Val<T | null> : Val<T>;
344
+ };
345
+ declare const createFunction: <C extends ExtensionBaseContext | never = never>(run: (context: C) => void) => Func<C>;
346
+ declare const createElement: <C extends ExtensionBaseComponent<any>>(component: C, props: C[typeof __props], ...children: Array<ExtensionElement | string>) => ExtensionElement;
347
+ declare const createFragment: (...children: Array<ExtensionElement | string>) => ExtensionElement;
348
+ declare const createView: <C extends ExtensionBaseViewContext>(run: (context: C) => ExtensionElement) => View<C>;
349
+ declare const createRuntime: <C extends ContextObject = ContextObject>(runtimeConfig: ExtensionRuntimeConfig<C>) => Extension;
350
+
351
+ export { type Brand, Components, type ContextObject, type ContextValue, type Extension, type ExtensionBaseComponents, type ExtensionBaseContext, type ExtensionBaseViewContext, type ExtensionBlockActionSpec, type ExtensionBlockActionViewContext, type ExtensionConfigurationViewContext, type ExtensionContentPieceViewContext, type ExtensionContentType, type ExtensionElement, type ExtensionElementSpec, type ExtensionElementViewContext, type ExtensionEnvironment, type ExtensionMetadata, type ExtensionRuntimeSpec, type ExtensionSpec, type Func, type MutableVal, type Val, type View, computed, createElement, createFragment, createFunction, createRuntime, createTemp, createView, effect, generateId, isVal };
@@ -0,0 +1 @@
1
+ const b=Symbol("usableEnv"),s=Symbol("value"),i=Symbol("id"),l=Symbol("componentName"),o={data:{},func:{},views:{},effects:[],currentScope:null},d=async(...e)=>{await Promise.all(o.effects.filter(t=>t.dependencies.some(n=>e.includes(n))).map(t=>t.run()))},m={},f=()=>`_${Math.random().toString(36).substring(2,9)}`,r=e=>e&&(typeof e=="object"||typeof e=="function")&&i in e&&s in e,y=new Proxy({},{get(e,t){const n=()=>{};return Object.defineProperty(n,l,{value:t}),n}});function w(e){if(!o.data.temp){const a=()=>o.data.temp[s];Object.defineProperty(a,i,{value:"temp"}),Object.defineProperty(a,s,{value:{},writable:!0}),o.data.temp=a}const t=f(),n=a=>{const p=o.data.temp;p[s][t]&&(p[s][t][s]=a),d(`temp.${t}`)},c=()=>o.data.temp[s][t][s];return Object.defineProperty(c,i,{value:`temp.${t}`}),Object.defineProperty(c,s,{value:e,writable:!0}),o.data.temp[s][t]=c,o.currentScope&&o.currentScope.temp.push(t),[c,n]}function g(e,t,n){const c=f();o.effects.push({[i]:c,dependencies:t.map(a=>a[i]),run:e}),o.currentScope&&o.currentScope.effects.push(c),n?.initial&&e()}const u=Object.assign(function(e,t){const[n,c]=w(e());return g(()=>{c(e())},t,{initial:!0}),n},{eq:(...e)=>{const t=e.filter(r);return u(()=>e.every(n=>(r(n)?n():n)===(r(e[0])?e[0]():e[0])),t)},neq:(...e)=>{const t=e.filter(r);return u(()=>e.some(n=>(r(n)?n():n)!==(r(e[0])?e[0]():e[0])),t)},gt:(e,t)=>{const n=[...r(e)?[e]:[],...r(t)?[t]:[]];return u(()=>(r(e)?e():e)>(r(t)?t():t),n)},lt:(e,t)=>{const n=[...r(e)?[e]:[],...r(t)?[t]:[]];return u(()=>(r(e)?e():e)<(r(t)?t():t),n)},and:(...e)=>{const t=e.filter(r);return u(()=>e.every(n=>r(n)?n():n),t)},or:(...e)=>{const t=e.filter(r);return u(()=>e.some(n=>r(n)?n():n),t)},not:e=>u(()=>!(r(e)?e():e),r(e)?[e]:[]),add:(...e)=>{const t=e.filter(r);return u(()=>e.reduce((n,c)=>n+(r(c)?c():c),0),t)},join:(...e)=>{const t=e.filter(r);return u(()=>e.reduce((n,c)=>n+(r(c)?c():c),""),t)},sub:(...e)=>{const t=e.filter(r);return u(()=>e.reduce((n,c)=>n-c(),0),t)},mul:(...e)=>{const t=e.filter(r);return u(()=>e.reduce((n,c)=>n*c(),1),t)},div:(e,t)=>{const n=[...r(e)?[e]:[],...r(t)?[t]:[]];return u(()=>(r(e)?e():e)/(r(t)?t():t),n)},mod:(e,t)=>{const n=[...r(e)?[e]:[],...r(t)?[t]:[]];return u(()=>(r(e)?e():e)%(r(t)?t():t),n)},neg:e=>u(()=>-(r(e)?e():e),r(e)?[e]:[]),when:(e,t,n)=>{const c=r(e)?[e]:[],a=r(t)?[t]:[],p=r(n)?[n]:[];return u(()=>(r(e)?e():e)?r(t)?t():t:n?r(n)?n():n:null,[...c,...a,...p])}}),S=e=>{const t=f(),n=e;return Object.defineProperty(n,i,{value:t}),o.func[t]=n,o.currentScope&&o.currentScope.func.push(t),n},P=(e,t,...n)=>({component:e[l]||"Fragment",slot:n,props:Object.fromEntries(Object.keys(t||{}).map(c=>{const a=t[c];return a&&a[i]?[c,a[i]]:[c,a]}))}),V=(...e)=>({component:"Fragment",slot:e,props:{}}),j=e=>{const t=f(),n={[i]:t,[s]:e};return o.views[t]=n,n},v=e=>{const t=m[e];t&&(t.func.forEach(n=>{delete o.func[n]}),t.temp.forEach(n=>{const c=o.data.temp;c()&&delete c()[n]}),t.effects.forEach(n=>{o.effects=o.effects.filter(c=>c[i]!==n)}))},E=e=>({getEnvironment:()=>o,getMetadata:()=>({__value:s,__id:i,__componentName:l,__usableEnv:b}),triggerEffects:d,generateRuntimeSpec:()=>({...e,onUninstall:e.onUninstall?.[i],onConfigure:e.onConfigure?.[i],configurationView:e.configurationView?.[i],contentPieceView:e.contentPieceView?.[i],blockActions:e.blockActions?.map(t=>({...t,view:t.view[i]})),elements:e.elements?.map(t=>({...t,view:t.view[i]})),page:e.page&&{mainView:e.page.mainView?.[i],sidePanelView:e.page.sidePanelView?.[i]}||void 0}),generateView:async(t,n,c)=>{const a=o.views[t]?.[s];if(a){o.currentScope={func:[],temp:[],effects:[],uid:c};const p=await a(n);return m[`view:${c}`]=o.currentScope,o.currentScope=null,p}return{component:"",slot:[]}},runFunction:async(t,n,c)=>{const a=o.func[t];a&&(o.currentScope={func:[],temp:[],effects:[],uid:c},await a(n),m[`func:${c}`]=o.currentScope,o.currentScope=null,v(`func:${c}`))},removeScope:v});export{y as Components,u as computed,P as createElement,V as createFragment,S as createFunction,E as createRuntime,w as createTemp,j as createView,g as effect,f as generateId,r as isVal};