@player-ui/markdown-plugin 0.8.0--canary.307.9645 → 0.8.0-next.0

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,69 +1,36 @@
1
1
  {
2
2
  "name": "@player-ui/markdown-plugin",
3
- "version": "0.8.0--canary.307.9645",
4
- "private": false,
5
- "publishConfig": {
6
- "registry": "https://registry.npmjs.org"
7
- },
3
+ "version": "0.8.0-next.0",
4
+ "main": "dist/cjs/index.cjs",
8
5
  "peerDependencies": {
9
- "@player-ui/player": "0.8.0--canary.307.9645",
10
- "@player-ui/types": "0.8.0--canary.307.9645"
6
+ "@player-ui/player": "0.8.0-next.0",
7
+ "@player-ui/types": "0.8.0-next.0"
11
8
  },
12
- "dependencies": {
13
- "tapable-ts": "^0.2.3",
14
- "mdast-util-from-markdown": "^2.0.0",
15
- "@babel/runtime": "7.15.4"
9
+ "devDependencies": {
10
+ "@player-ui/partial-match-fingerprint-plugin": "workspace:*",
11
+ "@player-ui/partial-match-registry": "workspace:*"
16
12
  },
17
- "main": "dist/index.cjs.js",
18
- "module": "dist/index.esm.js",
19
- "typings": "dist/index.d.ts",
13
+ "module": "dist/index.legacy-esm.js",
14
+ "types": "types/index.d.ts",
15
+ "bundle": "dist/MarkdownPlugin.native.js",
20
16
  "sideEffects": false,
21
- "license": "MIT",
22
- "repository": {
23
- "type": "git",
24
- "url": "https://github.com/player-ui/player-ui"
25
- },
26
- "bugs": {
27
- "url": "https://github.com/player-ui/player-ui/issues"
28
- },
29
- "homepage": "https://player-ui.github.io",
30
- "contributors": [
31
- {
32
- "name": "Adam Dierkens",
33
- "url": "https://github.com/adierkens"
34
- },
35
- {
36
- "name": "Spencer Hamm",
37
- "url": "https://github.com/spentacular"
38
- },
39
- {
40
- "name": "Harris Borawski",
41
- "url": "https://github.com/hborawski"
42
- },
43
- {
44
- "name": "Jeremiah Zucker",
45
- "url": "https://github.com/sugarmanz"
46
- },
47
- {
48
- "name": "Ketan Reddy",
49
- "url": "https://github.com/KetanReddy"
50
- },
51
- {
52
- "name": "Brocollie08",
53
- "url": "https://github.com/brocollie08"
54
- },
55
- {
56
- "name": "Kelly Harrop",
57
- "url": "https://github.com/kharrop"
58
- },
59
- {
60
- "name": "Alejandro Fimbres",
61
- "url": "https://github.com/lexfm"
62
- },
63
- {
64
- "name": "Rafael Campos",
65
- "url": "https://github.com/rafbcampos"
17
+ "exports": {
18
+ "./package.json": "./package.json",
19
+ "./dist/index.css": "./dist/index.css",
20
+ ".": {
21
+ "types": "./types/index.d.ts",
22
+ "import": "./dist/index.mjs",
23
+ "default": "./dist/cjs/index.cjs"
66
24
  }
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "src",
29
+ "types"
67
30
  ],
68
- "bundle": "./dist/markdown-plugin.prod.js"
31
+ "dependencies": {
32
+ "mdast-util-from-markdown": "^2.0.0",
33
+ "tapable-ts": "^0.2.3",
34
+ "tslib": "^2.6.2"
35
+ }
69
36
  }
@@ -0,0 +1,159 @@
1
+ import type { Asset, AssetWrapper } from "@player-ui/types";
2
+ import type { Mappers } from "../../types";
3
+
4
+ // Mock Asset Plugin implementation of the markdown plugin:
5
+
6
+ let depth = 0;
7
+
8
+ /**
9
+ * Wrap an Asset in an AssetWrapper
10
+ */
11
+ function wrapAsset(asset: Asset): AssetWrapper {
12
+ return {
13
+ asset,
14
+ };
15
+ }
16
+
17
+ /**
18
+ * Flatten a composite Asset with a single element
19
+ */
20
+ function flatSingleElementCompositeAsset(asset: Asset): Asset {
21
+ if (asset.type === "composite" && (asset.values as Asset[]).length === 1) {
22
+ return (asset.values as AssetWrapper[])[0].asset;
23
+ }
24
+
25
+ return asset;
26
+ }
27
+
28
+ /**
29
+ * Recursively applies a modifier to an Asset and its children.
30
+ */
31
+ function applyModifierToAssets({
32
+ types,
33
+ asset,
34
+ modifiers,
35
+ }: {
36
+ /**
37
+ * Types of Assets to apply the modifier to
38
+ */
39
+ types: string[];
40
+ /**
41
+ * Asset to be modified
42
+ */
43
+ asset: Asset;
44
+ /**
45
+ * Modifiers to be applied to the Asset
46
+ */
47
+ modifiers: any[];
48
+ }): Asset {
49
+ let modifiedAsset = asset;
50
+ if (types.includes(asset.type)) {
51
+ modifiedAsset = {
52
+ ...asset,
53
+ modifiers: [...((asset.modifiers as any) || []), ...modifiers],
54
+ };
55
+ }
56
+
57
+ if (asset.values) {
58
+ modifiedAsset = {
59
+ ...modifiedAsset,
60
+ values: (asset.values as Asset[]).map((a) =>
61
+ applyModifierToAssets({ types, asset: a, modifiers }),
62
+ ),
63
+ };
64
+ }
65
+
66
+ return modifiedAsset;
67
+ }
68
+
69
+ export const mockMappers: Mappers = {
70
+ text: ({ originalAsset, value }) => ({
71
+ id: `${originalAsset.id}-text-${depth++}`,
72
+ type: "text",
73
+ value,
74
+ }),
75
+ collection: ({ originalAsset, value }) => ({
76
+ id: `${originalAsset.id}-collection-${depth++}`,
77
+ type: "collection",
78
+ values: value.map(wrapAsset),
79
+ }),
80
+ strong: ({ originalAsset, value }) =>
81
+ flatSingleElementCompositeAsset({
82
+ id: `${originalAsset.id}-text-${depth++}`,
83
+ type: "composite",
84
+ values: value.map((v) =>
85
+ wrapAsset(
86
+ applyModifierToAssets({
87
+ asset: v,
88
+ types: ["text"],
89
+ modifiers: [
90
+ {
91
+ type: "tag",
92
+ value: "important",
93
+ },
94
+ ],
95
+ }),
96
+ ),
97
+ ),
98
+ }),
99
+ emphasis: ({ originalAsset, value }) =>
100
+ flatSingleElementCompositeAsset({
101
+ id: `${originalAsset.id}-text-${depth++}`,
102
+ type: "composite",
103
+ values: value.map((v) =>
104
+ wrapAsset(
105
+ applyModifierToAssets({
106
+ asset: v,
107
+ types: ["text"],
108
+ modifiers: [
109
+ {
110
+ type: "tag",
111
+ value: "emphasis",
112
+ },
113
+ ],
114
+ }),
115
+ ),
116
+ ),
117
+ }),
118
+ paragraph: ({ originalAsset, value }) =>
119
+ flatSingleElementCompositeAsset({
120
+ id: `${originalAsset.id}-composite-${depth++}`,
121
+ type: "composite",
122
+ values: value.map(wrapAsset),
123
+ }),
124
+ list: ({ originalAsset, value, ordered }) => ({
125
+ id: `${originalAsset.id}-list-${depth++}`,
126
+ type: "list",
127
+ values: value.map(wrapAsset),
128
+ ...(ordered && { metaData: { listType: "ordered" } }),
129
+ }),
130
+ image: ({ originalAsset, value, src }) => ({
131
+ id: `${originalAsset.id}-image-${depth++}`,
132
+ type: "image",
133
+ accessibility: value,
134
+ metaData: {
135
+ ref: src,
136
+ },
137
+ }),
138
+ link: ({ originalAsset, value, href }) =>
139
+ flatSingleElementCompositeAsset({
140
+ id: `${originalAsset.id}-link-${depth++}`,
141
+ type: "composite",
142
+ values: value.map((v) =>
143
+ wrapAsset(
144
+ applyModifierToAssets({
145
+ asset: v,
146
+ types: ["text", "image"],
147
+ modifiers: [
148
+ {
149
+ type: "link",
150
+ metaData: {
151
+ ref: href,
152
+ },
153
+ },
154
+ ],
155
+ }),
156
+ ),
157
+ ),
158
+ }),
159
+ };