git.s-ol.nu mmm / dc08e26
allow adding and removing of facets s-ol 3 years ago
5 changed file(s) with 48 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
4242
4343 -- active fileder
4444 -- (re)set every time @path changes
45 @active = @path\map @root\walk
45 @fileder = @path\map @root\walk
4646
4747 -- currently active facet
48 -- (re)set to default when @active changes
48 -- (re)set to default when @fileder changes
4949 @facet = ReactiveVar Key facet, 'mmm/dom'
5050 if MODE == 'CLIENT'
51 @active\subscribe (fileder) ->
51 @fileder\subscribe (fileder) ->
5252 return unless fileder
5353 last = @facet and @facet\get!
5454 @facet\set Key if last then last.type else 'mmm/dom'
118118 \append path_segment name, href
119119
120120 \append span 'view facet:', style: { 'margin-right': '0' }
121 \append @active\map (fileder) ->
121 \append @fileder\map (fileder) ->
122122 onchange = (_, e) ->
123123 { :type } = @facet\get!
124124 @facet\set Key name: e.target.value, :type
177177 warn "ERROR rendering content: #{msg}"
178178 div!
179179
180 active = @active\get!
180 active = @fileder\get!
181181
182182 return disp_error "fileder not found!" unless active
183183 return disp_error "facet not found!" unless prop
200200 -- active facet in inspect tab
201201 -- (re)set to match when @facet changes
202202 @inspect_prop = @facet\map (prop) ->
203 active = @active\get!
203 active = @fileder\get!
204204 key = active and active\find prop
205205 key = key.original if key and key.original
206206 key
212212 span 'inspector'
213213 @inspect_prop\map (current) ->
214214 current = current and current\tostring!
215 fileder = @active\get!
215 fileder = @fileder\get!
216216
217217 onchange = (_, e) ->
218 return if e.target.value == ''
219 { :name } = @facet\get!
220 @inspect_prop\set Key e.target.value
218 facet = e.target.value
219 return if facet == ''
220 @inspect_prop\set Key facet
221221
222222 with elements.select :onchange
223223 \append option '(none)', value: '', disabled: true, selected: not value
224224 if fileder
225225 for value in pairs fileder.facet_keys
226226 \append option value, :value, selected: value == current
227 @inspect\map (enabled) ->
228 if enabled
229 button 'close', onclick: (_, e) -> @inspect\set false
227
228 button 'rm', class: 'tight', onclick: (_, e) ->
229 if window\confirm "continuing will permanently remove the facet '#{@inspect_prop\get!}'."
230 fileder = @fileder\get!
231 fileder\set @inspect_prop\get!, nil
232 @fileder\set fileder -- trigger re-selection of active facet & inspector
233
234 button 'add', class: 'tight', onclick: (_, e) ->
235 facet = window\prompt "please enter the facet string ('name: type' or 'type'):", 'text/markdown'
236 return if not facet or facet == '' or facet == js.null
237 fileder = @fileder\get!
238 fileder\set facet, ''
239 @inspect_prop\set Key facet
240 @refresh!
241
242 button 'close', onclick: (_, e) -> @inspect\set false
230243 }
231244 \append with div class: @inspect_err\map (e) -> if e then 'error-wrap' else 'error-wrap empty'
232245 \append span "an error occured while rendering this view:"
134134
135135 __newindex: (t, k, v) ->
136136 -- get canonical Key instance
137 k = @facet_keys[k]
138 return unless k
139
140 rawset t, k, v
141
137 key = @facet_keys[k]
138
139 -- new creating, also create canonical Key
140 if not key
141 key = Key k
142 @facet_keys[key] = key
143
144 rawset t, key, v
145
146 -- when deleting, also delete canonical Key
142147 if not v
143 @facet_keys[k] = nil
148 @facet_keys[key] = nil
144149 }
145150
146151 -- this fails with JS objects from JSON.parse
242247
243248 -- find facet and type according to criteria, nil if no value or conversion path
244249 -- * ... - arguments like Key
245 find: (...) =>
246 want = Key ...
250 find: (key, key2, ...) =>
251 want = Key key, key2
247252
248253 -- filter facets by name
249254 matching = [ key for str, key in pairs @facet_keys when key.name == want.name ]
250255 return unless #matching > 0
251256
252257 -- get shortest conversion path
253 shortest_path, start = get_conversions want.type, [ key.type for key in *matching ]
258 shortest_path, start = get_conversions want.type, [ key.type for key in *matching ], ...
254259
255260 if start
256261 for key in *matching
291296 key = Key key
292297 value = key2
293298
294 if @facet_keys[key]
299 if value == nil
300 @store\remove_facet @path, key.name, key.type
301 elseif @facet_keys[key]
295302 @store\update_facet @path, key.name, key.type, value
296303 else
297304 @store\create_facet @path, key.name, key.type, value
11
22 export ^
33 PLUGINS = require '.plugins'
4 print "PLUGINS = ", PLUGINS
5555 {
5656 inp: 'text/html%+frag',
5757 out: 'mmm/dom',
58 cost: 1
58 cost: 0.1
5959 transform: if MODE == 'SERVER'
6060 (html, fileder) =>
6161 html = html\gsub '<mmm%-link%s+(.-)>(.-)</mmm%-link>', (attrs, text) ->
7171 > .inspect-btn {
7272 @include media-small() { display: none; }
7373 }
74
75 .tight {
76 margin-left: 0;
77 }
7478 }
7579
7680 .error-wrap {