rip-lang 3.13.75 → 3.13.77

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.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rip-lang",
3
- "version": "3.13.75",
3
+ "version": "3.13.77",
4
4
  "description": "A modern language that compiles to JavaScript",
5
5
  "type": "module",
6
6
  "main": "src/compiler.js",
package/src/browser.js CHANGED
@@ -79,6 +79,27 @@ async function processRipScripts() {
79
79
  }
80
80
  }
81
81
 
82
+ // Step 3b: Create app stash for data-src mode (skip if data-launch will handle it)
83
+ if (!globalThis.__ripApp && runtimeTag && !document.querySelector('script[data-launch]')) {
84
+ const stashFn = globalThis.stash;
85
+ if (stashFn) {
86
+ let initial = {};
87
+ const stateAttr = runtimeTag.getAttribute('data-state');
88
+ if (stateAttr) {
89
+ try { initial = JSON.parse(stateAttr); }
90
+ catch (e) { console.error('Rip: invalid data-state JSON:', e.message); }
91
+ }
92
+ const app = stashFn({ data: initial });
93
+ globalThis.__ripApp = app;
94
+ if (typeof window !== 'undefined') window.app = app;
95
+
96
+ const persistAttr = runtimeTag.getAttribute('data-persist');
97
+ if (persistAttr != null && globalThis.persistStash) {
98
+ globalThis.persistStash(app, { local: persistAttr === 'local' });
99
+ }
100
+ }
101
+ }
102
+
82
103
  if (compiled.length > 0) {
83
104
  let js = compiled.map(c => c.js).join('\n');
84
105
 
package/src/components.js CHANGED
@@ -1877,11 +1877,16 @@ export function installComponentSupport(CodeGenerator, Lexer) {
1877
1877
  }
1878
1878
  } else if (arg && !childrenVar) {
1879
1879
  const textVar = this.newTextVar();
1880
- const val = typeof arg === 'string' ? arg.valueOf() : null;
1881
- if (val && (val.startsWith('"') || val.startsWith("'") || val.startsWith('`'))) {
1882
- this._createLines.push(`${textVar} = document.createTextNode(${val});`);
1880
+ const exprCode = this.generateInComponent(arg, 'value');
1881
+ if (this.hasReactiveDeps(arg)) {
1882
+ this._createLines.push(`${textVar} = document.createTextNode('');`);
1883
+ const body = `${textVar}.data = ${exprCode};`;
1884
+ const effect = this._factoryMode
1885
+ ? `disposers.push(__effect(() => { ${body} }));`
1886
+ : `__effect(() => { ${body} });`;
1887
+ childrenSetupLines.push(effect);
1883
1888
  } else {
1884
- this._createLines.push(`${textVar} = document.createTextNode(${this.generateInComponent(arg, 'value')});`);
1889
+ this._createLines.push(`${textVar} = document.createTextNode(${exprCode});`);
1885
1890
  }
1886
1891
  childrenVar = textVar;
1887
1892
  props.push(`children: ${childrenVar}`);
@@ -2208,6 +2213,7 @@ function __handleComponentError(error, component) {
2208
2213
  class __Component {
2209
2214
  constructor(props = {}) {
2210
2215
  Object.assign(this, props);
2216
+ if (!this.app && globalThis.__ripApp) this.app = globalThis.__ripApp;
2211
2217
  const prev = __pushComponent(this);
2212
2218
  try { this._init(props); } catch (e) { __popComponent(prev); __handleComponentError(e, this); return; }
2213
2219
  __popComponent(prev);
package/src/ui.rip CHANGED
@@ -33,10 +33,12 @@ export { setContext, getContext, hasContext }
33
33
  # based access via get/set methods (e.g., stash.get('users[0].name')).
34
34
  # ==============================================================================
35
35
 
36
- STASH = Symbol('stash')
37
- SIGNALS = Symbol('signals')
38
- RAW = Symbol('raw')
39
- PROXIES = new WeakMap()
36
+ STASH = Symbol('stash')
37
+ SIGNALS = Symbol('signals')
38
+ RAW = Symbol('raw')
39
+ PERSISTED = Symbol('persisted')
40
+ PROXIES = new WeakMap()
41
+
40
42
  _keysVersion = 0
41
43
  _writeVersion = __state(0)
42
44
 
@@ -156,6 +158,28 @@ export raw = (proxy) -> if proxy?[RAW] then proxy[RAW] else proxy
156
158
 
157
159
  export isStash = (obj) -> obj?[STASH] is true
158
160
 
161
+ export persistStash = (app, opts = {}) ->
162
+ target = raw(app) or app
163
+ return if target[PERSISTED]
164
+ target[PERSISTED] = true
165
+ storage = if opts.local then localStorage else sessionStorage
166
+ storageKey = opts.key or '__rip_app'
167
+ try
168
+ saved = storage.getItem(storageKey)
169
+ if saved
170
+ savedData = JSON.parse(saved)
171
+ app.data[k] = v for k, v of savedData
172
+ catch
173
+ null
174
+ _save = ->
175
+ try storage.setItem storageKey, JSON.stringify(raw(app.data))
176
+ catch then null
177
+ __effect ->
178
+ _writeVersion.value
179
+ t = setTimeout _save, 2000
180
+ -> clearTimeout t
181
+ window.addEventListener 'beforeunload', _save
182
+
159
183
  # ==============================================================================
160
184
  # Resource — async data loading with reactive loading/error/data states
161
185
  #
@@ -930,6 +954,7 @@ export launch = (appBase = '', opts = {}) ->
930
954
 
931
955
  # Create the unified stash
932
956
  app = stash { components: {}, routes: {}, data: {} }
957
+ globalThis.__ripApp = app
933
958
 
934
959
  # Hydrate from bundle — any keys populate the stash
935
960
  app.data = bundle.data if bundle.data
@@ -938,24 +963,7 @@ export launch = (appBase = '', opts = {}) ->
938
963
 
939
964
  # Restore persisted state (overrides bundle defaults with saved user state)
940
965
  if persist and typeof sessionStorage isnt 'undefined'
941
- _storageKey = "__rip_#{appBase}"
942
- _storage = if persist is 'local' then localStorage else sessionStorage
943
- try
944
- saved = _storage.getItem(_storageKey)
945
- if saved
946
- savedData = JSON.parse(saved)
947
- app.data[k] = v for k, v of savedData
948
- catch
949
- null
950
- # Auto-save: debounce 2s after any stash write. Also save on unload.
951
- _save = ->
952
- try _storage.setItem _storageKey, JSON.stringify(raw(app.data))
953
- catch then null
954
- __effect ->
955
- _writeVersion.value
956
- t = setTimeout _save, 2000
957
- -> clearTimeout t
958
- window.addEventListener 'beforeunload', _save
966
+ persistStash app, local: persist is 'local', key: "__rip_#{appBase}"
959
967
 
960
968
  # Create components store and load component sources
961
969
  appComponents = createComponents()