@3sln/deck 0.0.8 → 0.0.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3sln/deck",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "A Vite plugin for building scalable, zero-config, Markdown-based component playgrounds and documentation sites.",
5
5
  "type": "module",
6
6
  "author": "Ray Stubbs",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@3sln/bones": "^0.0.4",
40
- "@3sln/dodo": "^0.0.5",
40
+ "@3sln/dodo": "^0.0.7",
41
41
  "@3sln/ngin": "^0.0.1",
42
42
  "fs-extra": "^11.3.2",
43
43
  "glob": "^10.3.10",
package/src/deck-demo.js CHANGED
@@ -8,6 +8,33 @@ import {stylesheet as highlightStylesheet, highlight} from './highlight.js';
8
8
 
9
9
  const {reconcile, h, div, button, pre, code, span, label, input, p} = dodo;
10
10
 
11
+ function getLanguageFromPath(path) {
12
+ if (!path) return 'plaintext';
13
+ const extension = path.split('.').pop().toLowerCase();
14
+ switch (extension) {
15
+ case 'js':
16
+ case 'mjs':
17
+ return 'javascript';
18
+ case 'cljs':
19
+ case 'clj':
20
+ case 'cljd':
21
+ return 'clojure';
22
+ case 'css':
23
+ return 'css';
24
+ case 'html':
25
+ case 'xml':
26
+ return 'xml';
27
+ case 'md':
28
+ return 'markdown';
29
+ case 'json':
30
+ return 'json';
31
+ case 'sh':
32
+ return 'bash';
33
+ default:
34
+ return 'plaintext';
35
+ }
36
+ }
37
+
11
38
  const {ObservableSubject, watch, zip, map, dedup} = reactiveFactory({dodo});
12
39
  const {withContainerSize} = resizeFactory({dodo});
13
40
 
@@ -35,16 +62,9 @@ const propertiesStyle = css`
35
62
  gap: 1em;
36
63
  margin-bottom: 0.75em;
37
64
  width: 250px;
38
- }
39
- .property-label {
40
- flex: 1;
41
- text-align: right;
42
- font-size: 0.9em;
43
65
  color: var(--text-color);
44
- opacity: 0.8;
45
66
  }
46
67
  .property-item input {
47
- flex: 2;
48
68
  flex-grow: 0;
49
69
  }
50
70
  input[type='text'] {
@@ -117,21 +137,25 @@ function propertyControl(engine, name) {
117
137
  return input({type: 'range', min: options.min, max: options.max, value}).on({
118
138
  input: e => engine.dispatch(new UpdatePropertyValue(name, e.target.valueAsNumber)),
119
139
  });
120
- case 'text':
121
- return input({type: 'text', value}).on({
122
- input: e => engine.dispatch(new UpdatePropertyValue(name, e.target.value)),
140
+ case 'checkbox':
141
+ return input({type: 'checkbox', checked: value}).on({
142
+ input: e => engine.dispatch(new UpdatePropertyValue(name, e.target.checked)),
123
143
  });
124
144
  default:
125
- return span('Unknown property type');
145
+ return input({type: options?.type ?? 'text', value}).on({
146
+ input: e => engine.dispatch(new UpdatePropertyValue(name, e.target.value)),
147
+ });
126
148
  }
127
149
  });
128
- return div({className: 'property-item'}, label({className: 'property-label'}, name), control);
150
+ return label({className: 'property-item'}, name, control);
129
151
  });
130
152
  }
131
153
 
132
154
  function createEngine(src, canonicalSrc) {
133
155
  const abortController = new AbortController();
134
156
  const sourceCode$ = new ObservableSubject('Loading...');
157
+ const textSrc = canonicalSrc || src;
158
+ const lang = getLanguageFromPath(textSrc);
135
159
 
136
160
  const demoState = new DemoState({
137
161
  activePanelIds: {},
@@ -160,7 +184,7 @@ function createEngine(src, canonicalSrc) {
160
184
  reconcile(container, [
161
185
  watch(sourceCode$, text =>
162
186
  pre(
163
- code({className: 'language-javascript'}, text).on({
187
+ code({className: `language-${lang}`}, text).on({
164
188
  $update: el => {
165
189
  delete el.dataset.highlighted;
166
190
  highlight(el);
@@ -179,6 +203,8 @@ function createEngine(src, canonicalSrc) {
179
203
  return;
180
204
  }
181
205
 
206
+ propertyPanelCreated = true;
207
+
182
208
  engine.dispatch(
183
209
  new CreateOrUpdatePanel({
184
210
  name: propsPanelName,
@@ -788,16 +814,22 @@ class DeckDemo extends HTMLElement {
788
814
  .key(p.name)
789
815
  .opaque()
790
816
  .on({
791
- $attach: el => {
817
+ $update: el => {
818
+ if (p.render === el._renderer) {
819
+ return;
820
+ }
821
+
822
+ el._aborter?.abort();
823
+
792
824
  const div = document.createElement('div');
793
825
  const shadow = div.attachShadow({mode: 'open'});
794
826
  const aborter = new AbortController();
795
827
 
796
- el.appendChild(div);
828
+ el.replaceChildren(div);
797
829
  el._aborter = aborter;
798
- },
799
- $update: el => {
800
- p.render(el.firstChild.shadowRoot, el._aborter.signal);
830
+ el._renderer = p.render;
831
+
832
+ p.render(shadow, aborter.signal);
801
833
  },
802
834
  $detach: el => {
803
835
  el._aborter?.abort();
package/src/highlight.js CHANGED
@@ -3,6 +3,7 @@ import javascript from 'highlight.js/lib/languages/javascript';
3
3
  import xml from 'highlight.js/lib/languages/xml';
4
4
  import clojure from 'highlight.js/lib/languages/clojure';
5
5
  import css from 'highlight.js/lib/languages/css';
6
+ import json from 'highlight.js/lib/languages/json';
6
7
  import githubStyle from 'highlight.js/styles/github.css?inline';
7
8
  import githubDarkStyle from 'highlight.js/styles/github-dark.css?inline';
8
9
  import {css as createSheet} from '@3sln/bones/style';
@@ -11,6 +12,7 @@ hljs.registerLanguage('javascript', javascript);
11
12
  hljs.registerLanguage('xml', xml); // For HTML
12
13
  hljs.registerLanguage('css', css);
13
14
  hljs.registerLanguage('clojure', clojure);
15
+ hljs.registerLanguage('json', json);
14
16
 
15
17
  export const stylesheet = createSheet`
16
18
  /* Light Theme */
package/src/main.js CHANGED
@@ -321,7 +321,6 @@ export async function renderDeck({target, initialCardsData, pinnedCardPaths}) {
321
321
 
322
322
  const syncNav = () => {
323
323
  const {q, c} = history.getQueryParams();
324
- console.log('q', q);
325
324
  engine.dispatch(new SelectCard(c));
326
325
  engine.dispatch(new SetSearchQuery(q));
327
326
  };