-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathspec.gts
1056 lines (996 loc) · 29.4 KB
/
spec.gts
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import {
contains,
field,
Component,
CardDef,
relativeTo,
linksToMany,
FieldDef,
containsMany,
getCardMeta,
type CardOrFieldTypeIcon,
BaseDef,
} from './card-api';
import StringField from './string';
import BooleanField from './boolean';
import CodeRef from './code-ref';
import MarkdownField from './markdown';
import {
FieldContainer,
Pill,
RealmIcon,
BoxelInput,
} from '@cardstack/boxel-ui/components';
import {
codeRefWithAbsoluteURL,
Loader,
loadCard,
isResolvedCodeRef,
isPrimitive,
} from '@cardstack/runtime-common';
import { eq } from '@cardstack/boxel-ui/helpers';
import GlimmerComponent from '@glimmer/component';
import BoxModel from '@cardstack/boxel-icons/box-model';
import BookOpenText from '@cardstack/boxel-icons/book-open-text';
import LayersSubtract from '@cardstack/boxel-icons/layers-subtract';
import GitBranch from '@cardstack/boxel-icons/git-branch';
import { DiagonalArrowLeftUp as ExportArrow } from '@cardstack/boxel-ui/icons';
import StackIcon from '@cardstack/boxel-icons/stack';
import AppsIcon from '@cardstack/boxel-icons/apps';
import LayoutList from '@cardstack/boxel-icons/layout-list';
import Brain from '@cardstack/boxel-icons/brain';
import { use, resource } from 'ember-resources';
import { TrackedObject } from 'tracked-built-ins';
export type SpecType = 'card' | 'field' | 'component' | 'app' | 'skill';
class SpecTypeField extends StringField {
static displayName = 'Spec Type';
}
const PRIMITIVE_INCOMPATIBILITY_MESSAGE =
'Examples are not currently supported for primitive fields';
class Isolated extends Component<typeof Spec> {
get defaultIcon() {
if (!this.args.model) {
return;
}
return this.args.model.constructor?.icon;
}
get icon() {
return this.cardDef?.icon;
}
@use private loadCardDef = resource(() => {
let cardDefObj = new TrackedObject<{ value: typeof BaseDef | undefined }>({
value: undefined,
});
(async () => {
try {
if (this.args.model.ref && this.args.model.id) {
let cardDef = await loadCard(this.args.model.ref, {
loader: myLoader(),
relativeTo: new URL(this.args.model.id),
});
cardDefObj.value = cardDef;
}
} catch (e) {
cardDefObj.value = undefined;
}
})();
return cardDefObj;
});
get cardDef() {
return this.loadCardDef.value;
}
get isPrimitiveField() {
return isPrimitive(this.cardDef);
}
get absoluteRef() {
if (!this.args.model.ref || !this.args.model.id) {
return undefined;
}
let url = new URL(this.args.model.id);
let ref = codeRefWithAbsoluteURL(this.args.model.ref, url);
if (!isResolvedCodeRef(ref)) {
throw new Error('ref is not a resolved code ref');
}
return ref;
}
private get realmInfo() {
return getCardMeta(this.args.model as CardDef, 'realmInfo');
}
<template>
<article class='container'>
<header class='header' aria-labelledby='title'>
<div class='box header-icon-container'>
{{#if this.icon}}
<this.icon width='35' height='35' role='presentation' />
{{else if this.defaultIcon}}
<this.defaultIcon width='35' height='35' role='presentation' />
{{/if}}
</div>
<div class='header-info-container'>
<h1 class='title' id='title' data-test-title>
<@fields.title />
</h1>
<p class='description' data-test-description>
<@fields.description />
</p>
</div>
</header>
<section class='readme section'>
<header class='row-header' aria-labelledby='readme'>
<BookOpenText width='20' height='20' role='presentation' />
<h2 id='readme'>Read Me</h2>
</header>
<div data-test-readme>
<@fields.readMe />
</div>
</section>
<section class='examples section'>
<header class='row-header' aria-labelledby='examples'>
<LayersSubtract width='20' height='20' role='presentation' />
<h2 id='examples'>Examples</h2>
</header>
{{#if (eq @model.specType 'field')}}
{{#if this.isPrimitiveField}}
<p
class='spec-example-incompatible-message'
data-test-spec-example-incompatible-primitives
>
<span>{{PRIMITIVE_INCOMPATIBILITY_MESSAGE}}</span>
</p>
{{else}}
<@fields.containedExamples @typeConstraint={{this.absoluteRef}} />
{{/if}}
{{/if}}
</section>
<section class='module section'>
<header class='row-header' aria-labelledby='module'>
<GitBranch width='20' height='20' role='presentation' />
<h2 id='module'>Module</h2>
</header>
<div class='code-ref-container'>
<FieldContainer @label='URL' @vertical={{true}}>
<div class='code-ref-row'>
<RealmIcon class='realm-icon' @realmInfo={{this.realmInfo}} />
<span class='code-ref-value' data-test-module-href>
{{@model.moduleHref}}
</span>
</div>
</FieldContainer>
<FieldContainer @label='Module Name' @vertical={{true}}>
<div class='code-ref-row'>
<ExportArrow class='exported-arrow' width='10' height='10' />
<div class='code-ref-value' data-test-exported-name>
{{@model.ref.name}}
</div>
<div class='exported-type' data-test-exported-type>
{{@model.specType}}
</div>
</div>
</FieldContainer>
</div>
</section>
</article>
<style scoped>
.container {
--boxel-spec-background-color: #ebeaed;
--boxel-spec-code-ref-background-color: #e2e2e2;
--boxel-spec-code-ref-text-color: #646464;
height: 100%;
min-height: max-content;
padding: var(--boxel-sp);
background-color: var(--boxel-spec-background-color);
}
.section {
margin-top: var(--boxel-sp);
padding-top: var(--boxel-sp);
border-top: 1px solid var(--boxel-400);
}
h1 {
margin: 0;
font-size: 18px;
font-weight: 600;
letter-spacing: var(--boxel-lsp-xs);
line-height: 1.2;
}
h2 {
margin: 0;
font: 600 var(--boxel-font-sm);
letter-spacing: var(--boxel-lsp-xs);
}
p {
margin-top: var(--boxel-sp-4xs);
margin-bottom: 0;
}
.title,
.description {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
text-wrap: pretty;
}
.box {
border: 1px solid var(--boxel-border-color);
border-radius: var(--boxel-border-radius-lg);
background-color: var(--boxel-light);
}
.header {
display: flex;
gap: var(--boxel-sp-sm);
}
.header-icon-container {
flex-shrink: 0;
height: var(--boxel-icon-xxl);
width: var(--boxel-icon-xxl);
display: flex;
align-items: center;
justify-content: center;
background-color: var(--boxel-100);
}
.header-info-container {
flex: 1;
align-self: center;
}
.row-header {
display: flex;
align-items: center;
gap: var(--boxel-sp-xs);
padding-bottom: var(--boxel-sp-lg);
}
.row-content {
margin-top: var(--boxel-sp-sm);
}
/* code ref container styles */
.code-ref-container {
display: flex;
flex-direction: column;
gap: var(--boxel-sp-xs);
}
.code-ref-row {
display: flex;
align-items: center;
gap: var(--boxel-sp-xs);
min-height: var(--boxel-form-control-height);
padding: var(--boxel-sp-xs);
background-color: var(
--boxel-spec-code-ref-background-color,
var(--boxel-100)
);
border: var(--boxel-border);
border-radius: var(--boxel-border-radius);
color: var(--boxel-spec-code-ref-text-color, var(--boxel-450));
}
.code-ref-value {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.exported-type {
margin-left: auto;
color: var(--boxel-450);
font: 500 var(--boxel-font-xs);
letter-spacing: var(--boxel-lsp);
text-transform: uppercase;
}
.exported-arrow {
min-width: 8px;
min-height: 8px;
}
.realm-icon {
width: 18px;
height: 18px;
border: 1px solid var(--boxel-dark);
}
.spec-example-incompatible-message {
font: var(--boxel-font-sm);
color: var(--boxel-450);
font-weight: 500;
margin-block: 0;
}
</style>
</template>
}
class Fitted extends Component<typeof Spec> {
get defaultIcon() {
if (!this.args.model) {
return;
}
return this.args.model.constructor?.icon;
}
get icon() {
return this.loadCardIcon.value;
}
@use private loadCardIcon = resource(() => {
let icon = new TrackedObject<{ value: CardOrFieldTypeIcon | undefined }>({
value: undefined,
});
(async () => {
try {
if (this.args.model.ref && this.args.model.id) {
let card = await loadCard(this.args.model.ref, {
loader: myLoader(),
relativeTo: new URL(this.args.model.id),
});
icon.value = card.icon;
}
} catch (e) {
icon.value = undefined;
}
})();
return icon;
});
<template>
<div class='fitted-template'>
<div class='thumbnail-section'>
{{#if this.icon}}
<this.icon width='35' height='35' role='presentation' />
{{else if this.defaultIcon}}
<this.defaultIcon width='35' height='35' role='presentation' />
{{/if}}
</div>
<div class='info-section'>
<h3 class='card-title' data-test-card-title><@fields.title /></h3>
<h4 class='card-description' data-test-card-description>
<@fields.description />
</h4>
</div>
{{#if @model.specType}}
<SpecTag @specType={{@model.specType}} />
{{/if}}
</div>
<style scoped>
@layer {
.fitted-template {
width: 100%;
height: 100%;
display: flex;
gap: var(--boxel-sp-xs);
padding: var(--boxel-sp-xs);
overflow: hidden;
align-items: center;
}
.thumbnail-section {
flex-shrink: 0;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.info-section {
width: 100%;
overflow: hidden;
}
.card-title {
margin-block: 0;
font: 600 var(--boxel-font-sm);
letter-spacing: var(--boxel-lsp-sm);
line-height: 1.25;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.card-description {
margin-top: var(--boxel-sp-4xs);
margin-bottom: 0;
color: var(--boxel-450);
font: 500 var(--boxel-font-xs);
letter-spacing: var(--boxel-lsp-xs);
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
:deep(.spec-tag-pill) {
height: max-content;
}
:deep(.spec-tag-pill .icon) {
width: 18px;
}
}
/* Aspect Ratio <= 1.0 (Vertical) */
@container fitted-card (aspect-ratio <= 1.0) {
.fitted-template {
flex-direction: column;
}
.thumbnail-section {
width: 100%;
height: 50cqmin;
}
.info-section {
text-align: center;
}
}
@container fitted-card (aspect-ratio <= 1.0) and (height <= 118px) {
.thumbnail-section {
display: none;
}
}
/* Vertical Tiles*/
/* Small Tile (150 x 170) */
@container fitted-card (aspect-ratio <= 1.0) and (150px <= width ) and (170px <= height) {
.thumbnail-section {
min-height: 70px;
}
.card-title {
-webkit-line-clamp: 3;
}
}
/* CardsGrid Tile (170 x 250) */
@container fitted-card (aspect-ratio <= 1.0) and (150px < width < 250px ) and (170px < height < 275px) {
.thumbnail-section {
height: auto;
aspect-ratio: 1 / 1;
}
.card-title {
-webkit-line-clamp: 2;
}
}
/* Tall Tile (150 x 275) */
@container fitted-card (aspect-ratio <= 1.0) and (150px <= width ) and (275px <= height) {
.thumbnail-section {
min-height: 85px;
}
.card-title {
font-size: var(--boxel-font-size);
-webkit-line-clamp: 4;
}
}
/* Large Tile (250 x 275) */
@container fitted-card (aspect-ratio <= 1.0) and (250px <= width ) and (275px <= height) {
.thumbnail-section {
min-height: 150px;
}
.card-title {
font-size: var(--boxel-font-size-sm);
-webkit-line-clamp: 3;
}
}
/* Vertical Cards */
@container fitted-card (aspect-ratio <= 1.0) and (400px <= width) {
.fitted-template {
padding: var(--boxel-sp);
gap: var(--boxel-sp);
}
.thumbnail-section {
min-height: 236px;
}
.card-title {
font-size: var(--boxel-font-size-med);
-webkit-line-clamp: 4;
}
}
/* Expanded Card (400 x 445) */
/* 1.0 < Aspect Ratio (Horizontal) */
@container fitted-card (1.0 < aspect-ratio) {
.thumbnail-section {
aspect-ratio: 1;
}
}
@container fitted-card (1.0 < aspect-ratio) and (height <= 65px) {
.info-section {
align-self: center;
}
}
/* Badges */
@container fitted-card (1.0 < aspect-ratio) and (width < 250px) {
.fitted-template {
padding: var(--boxel-sp-xxxs);
}
.thumbnail-section {
display: none;
}
}
/* Small Badge (150 x 40) */
@container fitted-card (1.0 < aspect-ratio) and (width < 250px) and (height < 65px) {
.card-title {
-webkit-line-clamp: 1;
font: 600 var(--boxel-font-xs);
}
.card-display-name {
margin-top: 0;
}
}
/* Medium Badge (150 x 65) */
/* Large Badge (150 x 105) */
@container fitted-card (1.0 < aspect-ratio) and (width < 250px) and (105px <= height) {
.card-title {
-webkit-line-clamp: 3;
}
}
/* Strips */
/* Single Strip (250 x 40) */
@container fitted-card (1.0 < aspect-ratio) and (250px <= width) and (height < 65px) {
.fitted-template {
padding: var(--boxel-sp-xxxs);
}
}
/* Double Strip (250 x 65) */
/* Triple Strip (250 x 105) */
/* Double Wide Strip (400 x 65) */
/* Triple Wide Strip (400 x 105) */
/* Horizontal Tiles */
/* Regular Tile (250 x 170) */
@container fitted-card (1.0 < aspect-ratio) and (250px <= width < 400px) and (170px <= height) {
.thumbnail-section {
height: 40%;
}
.card-title {
-webkit-line-clamp: 4;
font-size: var(--boxel-font-size);
}
}
/* Horizontal Cards */
/* Compact Card (400 x 170) */
@container fitted-card (1.0 < aspect-ratio) and (400px <= width) and (170px <= height) {
.thumbnail-section {
height: 100%;
}
}
/* Full Card (400 x 275) */
@container fitted-card (1.0 < aspect-ratio) and (400px <= width) and (275px <= height) {
.fitted-template {
padding: var(--boxel-sp);
gap: var(--boxel-sp);
}
.thumbnail-section {
max-width: 44%;
}
.card-title {
font-size: var(--boxel-font-size-med);
}
}
</style>
</template>
}
class Edit extends Component<typeof Spec> {
get defaultIcon() {
if (!this.args.model) {
return;
}
return this.args.model.constructor?.icon;
}
get icon() {
return this.cardDef?.icon;
}
@use private loadCardDef = resource(() => {
let cardDefObject = new TrackedObject<{
value: typeof BaseDef | undefined;
}>({
value: undefined,
});
(async () => {
try {
if (this.args.model.ref && this.args.model.id) {
let cardDef = await loadCard(this.args.model.ref, {
loader: myLoader(),
relativeTo: new URL(this.args.model.id),
});
cardDefObject.value = cardDef;
}
} catch (e) {
cardDefObject.value = undefined;
}
})();
return cardDefObject;
});
get cardDef() {
return this.loadCardDef.value;
}
get isPrimitiveField() {
return isPrimitive(this.cardDef);
}
get absoluteRef() {
if (!this.args.model.ref || !this.args.model.id) {
return undefined;
}
let url = new URL(this.args.model.id);
let ref = codeRefWithAbsoluteURL(this.args.model.ref, url);
if (!isResolvedCodeRef(ref)) {
throw new Error('ref is not a resolved code ref');
}
return ref;
}
private get realmInfo() {
return getCardMeta(this.args.model as CardDef, 'realmInfo');
}
<template>
<article class='container'>
<header class='header' aria-labelledby='title'>
<div class='box header-icon-container'>
{{#if this.icon}}
<this.icon width='35' height='35' role='presentation' />
{{else if this.defaultIcon}}
<this.defaultIcon width='35' height='35' role='presentation' />
{{/if}}
</div>
<div class='header-info-container'>
<div class='header-title-container' data-test-title>
<label for='spec-title' class='boxel-sr-only'>Title</label>
<@fields.title />
</div>
<div class='header-description-container' data-test-description>
<label
for='spec-description'
class='boxel-sr-only'
>Description</label>
<@fields.description />
</div>
</div>
</header>
<section class='readme section'>
<header class='row-header' aria-labelledby='readme'>
<BookOpenText width='20' height='20' role='presentation' />
<h2 id='readme'>Read Me</h2>
</header>
<div data-test-readme>
<@fields.readMe />
</div>
</section>
<section class='examples section'>
<header class='row-header' aria-labelledby='examples'>
<LayersSubtract width='20' height='20' role='presentation' />
<h2 id='examples'>Examples</h2>
</header>
{{#if (eq @model.specType 'field')}}
{{#if this.isPrimitiveField}}
<p
class='spec-example-incompatible-message'
data-test-spec-example-incompatible-primitives
>
<span>{{PRIMITIVE_INCOMPATIBILITY_MESSAGE}}</span>
</p>
{{else}}
<@fields.containedExamples @typeConstraint={{this.absoluteRef}} />
{{/if}}
{{else}}
<@fields.linkedExamples @typeConstraint={{this.absoluteRef}} />
{{/if}}
</section>
<section class='module section'>
<header class='row-header' aria-labelledby='module'>
<GitBranch width='20' height='20' role='presentation' />
<h2 id='module'>Module</h2>
</header>
<div class='code-ref-container'>
<FieldContainer @label='URL' @vertical={{true}}>
<div class='code-ref-row'>
<RealmIcon class='realm-icon' @realmInfo={{this.realmInfo}} />
<span class='code-ref-value' data-test-module-href>
{{@model.moduleHref}}
</span>
</div>
</FieldContainer>
<FieldContainer @label='Module Name' @vertical={{true}}>
<div class='code-ref-row'>
<ExportArrow class='exported-arrow' width='10' height='10' />
<div class='code-ref-value' data-test-exported-name>
{{@model.ref.name}}
</div>
<div class='exported-type' data-test-exported-type>
{{@model.specType}}
</div>
</div>
</FieldContainer>
</div>
</section>
</article>
<style scoped>
.container {
--boxel-spec-background-color: #ebeaed;
--boxel-spec-code-ref-background-color: #e2e2e2;
--boxel-spec-code-ref-text-color: #646464;
height: 100%;
min-height: max-content;
padding: var(--boxel-sp);
background-color: var(--boxel-spec-background-color);
}
.section {
margin-top: var(--boxel-sp);
padding-top: var(--boxel-sp);
border-top: 1px solid var(--boxel-400);
}
h2 {
margin: 0;
font: 600 var(--boxel-font-sm);
letter-spacing: var(--boxel-lsp-xs);
}
.box {
border: 1px solid var(--boxel-border-color);
border-radius: var(--boxel-border-radius-lg);
background-color: var(--boxel-light);
}
.header {
display: flex;
gap: var(--boxel-sp-sm);
}
.header-icon-container {
flex-shrink: 0;
height: var(--boxel-icon-xxl);
width: var(--boxel-icon-xxl);
display: flex;
align-items: center;
justify-content: center;
background-color: var(--boxel-100);
}
.header-info-container {
background-color: var(--boxel-light);
border-radius: var(--boxel-border-radius);
flex: 1;
align-self: center;
}
.header-info-container > div + div {
border-top: 1px solid var(--boxel-spec-background-color);
}
.header-title-container,
.header-description-container {
padding: var(--boxel-sp-xs);
}
.row-header {
display: flex;
align-items: center;
gap: var(--boxel-sp-xs);
padding-bottom: var(--boxel-sp-lg);
}
.row-content {
margin-top: var(--boxel-sp-sm);
}
/* code ref container styles */
.code-ref-container {
display: flex;
flex-direction: column;
gap: var(--boxel-sp-xs);
}
.code-ref-row {
display: flex;
align-items: center;
gap: var(--boxel-sp-xs);
min-height: var(--boxel-form-control-height);
padding: var(--boxel-sp-xs);
background-color: var(
--boxel-spec-code-ref-background-color,
var(--boxel-100)
);
border: var(--boxel-border);
border-radius: var(--boxel-border-radius);
color: var(--boxel-spec-code-ref-text-color, var(--boxel-450));
}
.code-ref-value {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.exported-type {
margin-left: auto;
color: var(--boxel-450);
font: 500 var(--boxel-font-xs);
letter-spacing: var(--boxel-lsp);
text-transform: uppercase;
}
.exported-arrow {
min-width: 8px;
min-height: 8px;
}
.realm-icon {
width: 18px;
height: 18px;
border: 1px solid var(--boxel-dark);
}
.spec-example-incompatible-message {
font: var(--boxel-font-sm);
color: var(--boxel-450);
font-weight: 500;
margin-block: 0;
}
</style>
</template>
}
class SpecTitleField extends StringField {
static displayName = 'Spec Title';
static edit = class Edit extends Component<typeof this> {
get placeholder() {
const hasFieldName = Boolean(this.args.fieldName);
if (hasFieldName) {
return 'Enter ' + this.args.fieldName;
}
return undefined;
}
<template>
<BoxelInput
@id='spec-title'
@value={{@model}}
@onInput={{@set}}
@placeholder={{this.placeholder}}
class='spec-title-input'
/>
<style scoped>
.spec-title-input {
font-size: 18px;
font-weight: 600;
letter-spacing: var(--boxel-lsp-xs);
padding: var(--boxel-sp-4xs) 0 var(--boxel-sp-4xs) var(--boxel-sp-xs);
}
.spec-title-input::placeholder {
color: var(--boxel-400);
}
</style>
</template>
};
}
class SpecDescriptionField extends StringField {
static displayName = 'Spec Description';
static edit = class Edit extends Component<typeof this> {
get placeholder() {
const hasFieldName = Boolean(this.args.fieldName);
if (hasFieldName) {
return 'Enter ' + this.args.fieldName;
}
return undefined;
}
<template>
<BoxelInput
@id='spec-description'
@value={{@model}}
@onInput={{@set}}
@placeholder={{this.placeholder}}
class='spec-description-input'
/>
<style scoped>
.spec-description-input {
padding: var(--boxel-sp-4xs) 0 var(--boxel-sp-4xs) var(--boxel-sp-xs);
}
.spec-description-input::placeholder {
color: var(--boxel-400);
}
</style>
</template>
};
}
export class Spec extends CardDef {
static displayName = 'Spec';
static icon = BoxModel;
@field readMe = contains(MarkdownField);
@field ref = contains(CodeRef);
@field specType = contains(SpecTypeField);
@field isField = contains(BooleanField, {
computeVia: function (this: Spec) {
return this.specType === 'field';
},
});
@field isCard = contains(BooleanField, {
computeVia: function (this: Spec) {
return (
this.specType === 'card' ||
this.specType === 'app' ||
this.specType === 'skill'
);
},
});
@field isComponent = contains(BooleanField, {
computeVia: function (this: Spec) {
return this.specType === 'component';
},
});
@field moduleHref = contains(StringField, {
computeVia: function (this: Spec) {
if (!this.ref || !this.ref.module) {
return undefined;
}
return new URL(this.ref.module, this[relativeTo]).href;
},
});
@field linkedExamples = linksToMany(CardDef);
@field containedExamples = containsMany(FieldDef, { isUsed: true });
@field title = contains(SpecTitleField);
@field description = contains(SpecDescriptionField);
static isolated = Isolated;
static embedded = class Embedded extends Component<typeof this> {
get icon() {
return this.args.model.constructor?.icon;
}
<template>
<article class='embedded-spec'>
<div class='header-icon-container'>
<this.icon width='30' height='30' role='presentation' />
</div>
<div class='header-info-container'>
<h3 class='title'><@fields.title /></h3>
<p class='description'><@fields.description /></p>
</div>
{{#if @model.specType}}
<SpecTag @specType={{@model.specType}} />
{{/if}}
</article>
<style scoped>
.embedded-spec {
display: flex;
align-items: center;
gap: var(--boxel-sp-sm);
padding: var(--boxel-sp-xs);
}
.header-icon-container {
flex-shrink: 0;
height: var(--boxel-icon-xl);
width: var(--boxel-icon-xl);
display: flex;
align-items: center;
justify-content: center;
background-color: var(--boxel-100);
border: 1px solid var(--boxel-border-color);
border-radius: var(--boxel-border-radius-lg);
background-color: var(--boxel-light);
}
.header-info-container {
flex: 1;
}
.title {
margin: 0;
font: 600 var(--boxel-font-sm);
letter-spacing: var(--boxel-lsp-xs);
}
.description {
margin: 0;
color: var(--boxel-500);
font: var(--boxel-font-size-xs);
letter-spacing: var(--boxel-lsp-xs);
}
</style>
</template>
};
static fitted = Fitted;
static edit = Edit;
}
interface SpecTagSignature {
Element: HTMLDivElement;
Args: {
specType: string;
};