zebflow 0.10.3

Reactive web automation platform — pipelines, templates, and real-time collaboration in a single binary.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
// zeb_ssr_init.js — Zebflow SSR integration and browser-library placeholders.
//
// Loaded once into the deno_core JsRuntime at startup.
// Sets up all globals that RWE templates expect: h, Fragment, React,
// useState, useEffect, useRef, useMemo, useCallback, useContext, useReducer,
// createContext, usePageState, useRouter, Link, and the internal
// __rweRenderToString / __rweWrapWithPageState helpers called from Rust.

(function () {
  "use strict";

  // ---------------------------------------------------------------------------
  // HTML / attribute escaping
  // ---------------------------------------------------------------------------
  function escHtml(s) {
    if (s == null) return "";
    return String(s)
      .replace(/&/g, "&")
      .replace(/</g, "&lt;")
      .replace(/>/g, "&gt;");
  }

  function escAttr(s) {
    if (s == null) return "";
    return String(s)
      .replace(/&/g, "&amp;")
      .replace(/</g, "&lt;")
      .replace(/>/g, "&gt;")
      .replace(/"/g, "&quot;");
  }

  function base64EncodeUtf8(text) {
    if (typeof btoa !== "undefined") {
      return btoa(unescape(encodeURIComponent(text)));
    }
    if (typeof Buffer !== "undefined") {
      return Buffer.from(text, "utf-8").toString("base64");
    }
    var encodedText = encodeURIComponent(String(text || ""));
    var bytes = [];
    for (var j = 0; j < encodedText.length; j++) {
      var ch = encodedText.charAt(j);
      if (ch === "%") {
        bytes.push(parseInt(encodedText.slice(j + 1, j + 3), 16));
        j += 2;
      } else {
        bytes.push(encodedText.charCodeAt(j));
      }
    }
    var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    var out = "";
    for (var i = 0; i < bytes.length; i += 3) {
      var b1 = bytes[i];
      var b2 = i + 1 < bytes.length ? bytes[i + 1] : 0;
      var b3 = i + 2 < bytes.length ? bytes[i + 2] : 0;
      var triplet = (b1 << 16) | (b2 << 8) | b3;
      out += chars[(triplet >> 18) & 63];
      out += chars[(triplet >> 12) & 63];
      out += i + 1 < bytes.length ? chars[(triplet >> 6) & 63] : "=";
      out += i + 2 < bytes.length ? chars[triplet & 63] : "=";
    }
    return out;
  }

  // Shared Zeb React primitives; loaded before this adapter in every V8 worker.
  var { h, Fragment, renderToString, createContext, useState, useEffect,
    useLayoutEffect, useRef, useMemo, useCallback, useContext, useReducer,
    useId, useImperativeHandle, useSyncExternalStore, forwardRef, memo,
    createPortal } = globalThis.__zebReact;
  function useInsertionEffect() {} // SSR-only legacy no-op.

  // ---------------------------------------------------------------------------
  // Page-state context — shared mutable state across all components on a page
  // ---------------------------------------------------------------------------
  var PageStateContext = createContext(null);

  function createUsePageState() {
    return function usePageState(keyOrInitial, defaultValue) {
      var isKeyed = typeof keyOrInitial === "string";
      var ctx = useContext(PageStateContext);
      if (isKeyed) {
        var key = keyOrInitial;
        if (ctx && typeof ctx === "object") {
          var value = key in ctx ? ctx[key] : defaultValue;
          var setter = function (v) { if (ctx.setPageState) ctx.setPageState(function (p) { var o = {}; o[key] = v; return o; }); };
          return [value, setter];
        }
        // SSR root: no-op setter, just return default
        return [defaultValue, function () {}];
      }
      if (ctx && typeof ctx === "object") return ctx;
      return Object.assign({}, keyOrInitial || {}, { setPageState: function () {} });
    };
  }

  // ---------------------------------------------------------------------------
  // Navigation — SSR no-ops; browser hydration script has real implementations
  // ---------------------------------------------------------------------------
  // Where the request arrived. The server is rendering one fixed URL, so these
  // read the payload the pipeline injected rather than subscribing to anything
  // — there is nothing here that can change mid-render.
  function usePathname() {
    var ctx = globalThis.ctx || {};
    return typeof ctx.route === "string" && ctx.route ? ctx.route : "/";
  }

  function useSearchParams() {
    var ctx = globalThis.ctx || {};
    var entries = [];
    var query = ctx.query;
    if (query && typeof query === "object") {
      for (var key in query) {
        if (Object.prototype.hasOwnProperty.call(query, key)) {
          entries.push([key, String(query[key])]);
        }
      }
    }
    // deno_core installs no browser URLSearchParams. Keep this a local,
    // read-only query view rather than installing a partial web API globally.
    // Rust's URL implementation owns decoding and canonical form encoding.
    var snapshot = Deno.core.ops.op_rwe_search_params_snapshot(
      typeof ctx.search === "string" ? ctx.search : null,
      entries
    );
    var pairs = snapshot.entries;
    var scalarString = function(value) {
      if (typeof value === "symbol") throw new TypeError("Cannot convert a Symbol value to a string");
      return String(value).toWellFormed();
    };
    var readonly = function() { throw new TypeError("Search params are read-only; use router.push or router.replace."); };
    var view = {
      get: function(name) {
        name = scalarString(name);
        for (var pair of pairs) if (pair[0] === name) return pair[1];
        return null;
      },
      getAll: function(name) {
        name = scalarString(name);
        return pairs.filter(function(pair) { return pair[0] === name; }).map(function(pair) { return pair[1]; });
      },
      has: function(name, value) {
        name = scalarString(name);
        var matchValue = value !== undefined;
        if (matchValue) value = scalarString(value);
        return pairs.some(function(pair) { return pair[0] === name && (!matchValue || pair[1] === value); });
      },
      entries: function() { return pairs.map(function(pair) { return pair.slice(); })[Symbol.iterator](); },
      keys: function() { return pairs.map(function(pair) { return pair[0]; })[Symbol.iterator](); },
      values: function() { return pairs.map(function(pair) { return pair[1]; })[Symbol.iterator](); },
      forEach: function(callback, thisArg) {
        if (typeof callback !== "function") throw new TypeError("Search params callback must be a function");
        pairs.forEach(function(pair) { callback.call(thisArg, pair[1], pair[0], view); });
      },
      toString: function() { return snapshot.encoded; },
      size: pairs.length,
      append: readonly,
      delete: readonly,
      set: readonly,
      sort: readonly,
    };
    view[Symbol.iterator] = view.entries;
    return Object.freeze(view);
  }

  // The server has no history and nobody clicking, so every method is a
  // no-op. That is the correct behaviour for a server, not a placeholder:
  // the same component code runs in both places and must not branch.
  function useRouter() {
    return {
      push: function (_href) {},
      replace: function (_href) {},
      back: function () {},
      forward: function () {},
      refresh: function () {},
      prefetch: function (_href) {},
    };
  }

  function Link(props) {
    // Render as plain <a> for SEO / SSR.
    var href = props.href;
    var children = props.children;
    var rest = {};
    for (var k in props) {
      if (k !== "href" && k !== "children") rest[k] = props[k];
    }
    return h("a", Object.assign({ href: href }, rest), children);
  }

  // ---------------------------------------------------------------------------
  // wrapWithPageState — wraps a Page component with page-state context
  // ---------------------------------------------------------------------------
  function wrapWithPageState(Page, input) {
    input = input || {};
    // Set up context so usePageState() in any child component works.
    var ctxValue = Object.assign({}, input, { setPageState: function () {} });
    return h(PageStateContext.Provider, { value: ctxValue }, h(Page, input));
  }

  // ---------------------------------------------------------------------------
  // Install all globals
  // ---------------------------------------------------------------------------
  globalThis.h = h;
  globalThis.Fragment = Fragment;
  globalThis.React = { createElement: h, Fragment: Fragment };
  globalThis.createElement = h;

  globalThis.useState = useState;
  globalThis.useEffect = useEffect;
  globalThis.useLayoutEffect = useLayoutEffect;
  globalThis.useInsertionEffect = useInsertionEffect;
  globalThis.useRef = useRef;
  globalThis.useMemo = useMemo;
  globalThis.useCallback = useCallback;
  globalThis.useContext = useContext;
  globalThis.useReducer = useReducer;
  globalThis.useId = useId;
  globalThis.useImperativeHandle = useImperativeHandle;
  globalThis.useSyncExternalStore = useSyncExternalStore;
  globalThis.forwardRef = forwardRef;
  globalThis.memo = memo;
  globalThis.createPortal = createPortal;

  globalThis.createContext = createContext;
  globalThis.usePageState = createUsePageState();
  globalThis.useRouter = useRouter;
  globalThis.usePathname = usePathname;
  globalThis.useSearchParams = useSearchParams;
  globalThis.Link = Link;
  globalThis.cx = function cx() {
    var out = [];
    for (var i = 0; i < arguments.length; i++) {
      if (arguments[i]) out.push(arguments[i]);
    }
    return out.join(" ");
  };

  // ---------------------------------------------------------------------------
  // zeb/use SSR stubs — safe server-side fallbacks (bundle only runs client-side)
  // ---------------------------------------------------------------------------
  globalThis.useDebounce = function(value) { return value; };
  globalThis.useThrottle = function(value) { return value; };
  globalThis.useLocalStorage = function(key, init) { return [init, function() {}]; };
  globalThis.useClipboard = function() { return { copied: false, copy: function() {} }; };
  globalThis.useTemporaryState = function(init) { return [init, function() {}]; };
  globalThis.useWindowEvent = function() {};
  globalThis.useLazyModule = function() { return [null, true, null]; };
  // useSearchParams deliberately absent here: it belongs to zeb/react and is
  // installed above. A second one with a [value, setter] shape used to be
  // declared later in this file and silently replaced it.
  globalThis.useSplitPane = function() { return { current: null }; };
  globalThis.useClickAway = function() { return { current: null }; };
  globalThis.useInterval = function() {};
  globalThis.useGeolocation = function() { return { loading: true, error: null, coords: null }; };
  globalThis.useTree = function() {
    return { expanded: new Set(), isExpanded: function() { return false; }, toggle: function() {}, expand: function() {}, collapse: function() {}, expandAll: function() {}, collapseAll: function() {} };
  };

  // ---------------------------------------------------------------------------
  // zeb/prosemirror — engine only, browser only. `zeb/ui/editor` renders a
  // document on the server itself and mounts the engine in an effect, so
  // nothing here needs a server-side stand-in.
  // ---------------------------------------------------------------------------

  // ---------------------------------------------------------------------------
  // Devicon helpers — no-ops during SSR. The marks are a platform
  // stylesheet now; these remain so a template calling them still renders.
  // ---------------------------------------------------------------------------
  globalThis.ensureDevicons = function() {};
  globalThis.dbKindIconClass = function() { return ""; };
  globalThis.dbObjectIconClass = function() { return ""; };

  // ---------------------------------------------------------------------------
  // zeb/threejs SSR stubs — Three.js is WebGL/browser-only.
  // Canvas/ThreeCanvas/ThreeScene render placeholder divs.
  // Three.js classes are empty constructors — only ever called inside useEffect,
  // which does not run during SSR renderToString.
  // ---------------------------------------------------------------------------
  globalThis.Canvas = function(props) {
    return h('div', { className: (props && props.className) || 'w-full h-full' });
  };
  globalThis.ThreeCanvas = globalThis.Canvas;
  globalThis.ThreeContext = createContext(null);
  globalThis.ThreeScene = function(props) {
    return h('div', {
      'data-zeb-lib': 'threejs',
      'data-zeb-wrapper': 'ThreeScene',
      'data-config': JSON.stringify((props && props.config) || {}),
      id: props && props.id,
      className: (props && props.className) || 'w-full h-full',
    });
  };
  globalThis.useThree = function() { return {}; };
  globalThis.useFrame = function() {};
  globalThis.OrbitControls = function() { return null; };
  globalThis.createSceneRuntime = function() { return {}; };
  globalThis.mountThreeScene = function() {};
  globalThis.ensureThree = function() { return {}; };
  globalThis.MathUtils = {};
  globalThis.REVISION = '183';
  (function() {
    var _cls = function() {};
    var _names = [
      'Scene','PerspectiveCamera','OrthographicCamera','WebGLRenderer',
      'Mesh','Group','Object3D','InstancedMesh','Points','Line',
      'BoxGeometry','SphereGeometry','PlaneGeometry','CylinderGeometry',
      'TorusGeometry','TorusKnotGeometry','ConeGeometry','RingGeometry','CircleGeometry','BufferGeometry',
      'MeshStandardMaterial','MeshBasicMaterial','MeshPhongMaterial','MeshLambertMaterial',
      'MeshNormalMaterial','MeshToonMaterial','MeshPhysicalMaterial','ShaderMaterial',
      'DirectionalLight','PointLight','SpotLight','AmbientLight','HemisphereLight',
      'Vector2','Vector3','Vector4','Quaternion','Euler','Matrix4','Color',
      'Raycaster','Clock','AnimationMixer','TextureLoader','CubeTextureLoader','Texture'
    ];
    for (var i = 0; i < _names.length; i++) { globalThis[_names[i]] = _cls; }
  })();

  // ---------------------------------------------------------------------------
  // zeb/threejs-vrm SSR stubs — VRM viewer is WebGL/browser-only.
  // ---------------------------------------------------------------------------
  globalThis.VrmViewer = function(props) {
    var cfg = JSON.stringify({
      modelUrl: (props && (props.modelUrl || props.model_url)) || '',
      height: (props && props.height) || '400px',
      background: (props && props.background) || 'transparent',
      autoRotate: !!(props && props.autoRotate),
      cameraZ: (props && props.cameraZ) || 1.5,
    });
    return h('div', {
      'data-zeb-lib': 'threejs-vrm',
      'data-zeb-wrapper': 'VrmViewer',
      'data-config': cfg,
      id: props && props.id,
      className: (props && props.className) || 'w-full h-full',
      style: { width: '100%', height: (props && props.height) || '400px' },
    });
  };
  globalThis.mountVrmViewer = function() {};

  // ---------------------------------------------------------------------------
  // zeb/deckgl SSR stubs — Deck.gl is WebGL/browser-only.
  // ---------------------------------------------------------------------------
  globalThis.DeckMap = function(props) {
    var cfg = JSON.stringify({
      initialViewState: props && props.initialViewState,
      controller: !props || props.controller !== false,
      layers: (props && props.layers) || [],
      stateKey: (props && props.stateKey) || null,
      layerKey: (props && props.layerKey) || null,
      background: (props && props.background) || 'transparent',
    });
    return h('div', {
      'data-zeb-lib': 'deckgl',
      'data-zeb-wrapper': 'DeckMap',
      'data-config': cfg,
      id: props && props.id,
      className: props && props.className,
      style: { width: '100%', height: (props && props.height) || '400px' },
    });
  };
  globalThis.deckgl = {};
  globalThis.buildLayer = function() { return null; };
  globalThis.buildLayers = function() { return []; };
  globalThis.mountDeckMap = function() {};
  globalThis.ensureDeck = function() {};
  globalThis.createDeckMapRuntime = function() { return {}; };

  // ---------------------------------------------------------------------------
  // zeb/d3 SSR stubs — D3 chart components render placeholder divs.
  // ---------------------------------------------------------------------------
  globalThis.d3 = {};
  globalThis.useD3 = function(callback, deps) {
    var ref = useRef(null);
    useEffect(function() {
      if (!ref.current) return;
      return callback(ref.current, {});
    }, deps || []);
    return ref;
  };
  globalThis.D3Bars = function(props) {
    var cfg = JSON.stringify({
      type: (props && props.type) || 'bar',
      data: (props && props.data) || [],
      xKey: props && props.xKey,
      yKey: props && props.yKey,
      stateKey: props && props.stateKey,
      height: (props && props.height) || '260px',
      colorScheme: props && props.colorScheme,
      area: !!(props && props.area),
    });
    return h('div', {
      'data-zeb-lib': 'd3',
      'data-zeb-wrapper': 'D3Bars',
      'data-config': cfg,
      id: props && props.id,
      className: props && props.className,
      style: { width: '100%', height: (props && props.height) || '260px' },
    });
  };

  // ---------------------------------------------------------------------------
  // zeb/graphui SSR stubs — graph canvas is browser-only.
  // ---------------------------------------------------------------------------
  globalThis.GraphCanvas = function(props) {
    return h('div', {
      'data-zeb-lib': 'graphui',
      'data-zeb-wrapper': 'GraphCanvas',
      id: props && props.id,
      className: (props && props.className) || 'w-full h-full',
    });
  };
  globalThis.PipelineGraph = function PipelineGraph(props) {
    return h('div', {
      'data-zeb-lib': 'graphui',
      'data-zeb-wrapper': 'PipelineGraph',
      id: props && props.id,
      className: (props && props.className) || 'w-full h-full',
    });
  };

  // ---------------------------------------------------------------------------
  // zeb/codemirror SSR stubs — code editor is browser-only.
  // ---------------------------------------------------------------------------
  globalThis.CodeEditor = function(props) {
    return h('div', {
      'data-zeb-lib': 'codemirror',
      'data-zeb-wrapper': 'CodeEditor',
      id: props && props.id,
      className: (props && props.className) || 'w-full h-full',
    });
  };

  // ---------------------------------------------------------------------------
  // zeb/markdown SSR stubs — Markdown component renders an encoded placeholder.
  // ---------------------------------------------------------------------------
  globalThis.Markdown = function(props) {
    var text = (props && props.content) || (typeof (props && props.children) === 'string' ? props.children : '') || '';
    var encoded = base64EncodeUtf8(text);
    return h('div', {
      'data-zeb-lib': 'markdown',
      'data-rwe-md': encoded,
      className: 'rwe-md-placeholder' + ((props && props.className) ? (' ' + props.className) : ''),
    });
  };

  // ---------------------------------------------------------------------------
  // Page-state bridge — SSR no-ops.
  // The real implementations are installed by build_client_module in render.rs
  // inside __RweRoot after hydration. These stubs prevent ReferenceError when
  // zeb/* library bundles (e.g. zeb/prosemirror) call the bridge during SSR.
  // ---------------------------------------------------------------------------
  globalThis.__rweSetPageState = function() {};
  globalThis.__rwePageState = {};

  // Internal helpers called by Rust after loading each page module.
  // Keep RWE's existing partial-render error contract. Direct engine consumers
  // get exceptions; platform SSR retains its observable component-error marker.
  globalThis.__rweRenderToString = function (node) {
    return renderToString(node, { onError: function (error) {
      return '<!-- RWE component error: ' + escHtml(String(error)).replace(/--/g, '&#45;&#45;') + ' -->';
    } });
  };
  globalThis.__rweWrapWithPageState = wrapWithPageState;

  // ---------------------------------------------------------------------------
  // Island support for SSR — mirrors the client-side h() interceptor.
  // SSR versions always render children but emit the data-island-id marker so
  // the DOM structure matches the client vdom (preventing hydration mismatches).
  // __islandCounter is also reset from Rust in deno_worker.rs before each render.
  // ---------------------------------------------------------------------------
  globalThis.__islandCounter = 0;

  var __origSSRh = globalThis.h;

  function __IslandOff(p) { return p.children; }

  function __IslandOnView(p) {
    return __origSSRh('div', { 'data-island-id': p.id, 'data-hydrate': 'onview' }, p.children);
  }

  function __IslandOnInteract(p) {
    return __origSSRh('div', { 'data-island-id': p.id, 'data-hydrate': 'oninteract' }, p.children);
  }

  globalThis.h = function(type, props) {
    var args = Array.prototype.slice.call(arguments, 2);
    if (props && props.hydrate && props.hydrate !== 'onload') {
      var mode = props.hydrate;
      var id = 'island-' + (globalThis.__islandCounter++);
      var newProps = Object.assign({}, props);
      delete newProps.hydrate;
      newProps['data-island-id'] = id;
      var el = __origSSRh.apply(null, [type, newProps].concat(args));
      if (mode === 'off')        return __IslandOff({ children: el });
      if (mode === 'onview')     return __IslandOnView({ id: id, children: el });
      if (mode === 'oninteract') return __IslandOnInteract({ id: id, children: el });
    }
    return __origSSRh.apply(null, [type, props].concat(args));
  };
})();