dtable-ui-component 4.4.2 → 4.4.3-2
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/lib/AutoNumberFormatter/index.js +14 -7
- package/lib/ButtonFormatter/index.js +16 -9
- package/lib/CTimeFormatter/index.js +16 -9
- package/lib/CheckboxEditor/index.js +15 -8
- package/lib/CheckboxFormatter/index.js +15 -8
- package/lib/CollaboratorEditor/index.js +29 -21
- package/lib/CollaboratorEditor/mb-collaborator-editor-popover/index.js +32 -25
- package/lib/CollaboratorEditor/pc-collaborator-editor-popover/index.js +25 -18
- package/lib/CollaboratorFormatter/index.js +19 -12
- package/lib/CollaboratorItem/index.js +17 -10
- package/lib/CreatorFormatter/index.js +19 -12
- package/lib/DTableCommonAddTool/index.js +13 -6
- package/lib/DTableCustomizeCollaboratorSelect/index.js +26 -18
- package/lib/DTableCustomizeSelect/index.js +23 -15
- package/lib/DTableFiltersPopover/constants/index.js +38 -33
- package/lib/DTableFiltersPopover/index.js +38 -31
- package/lib/DTableFiltersPopover/utils/filter-item-utils.js +53 -46
- package/lib/DTableFiltersPopover/utils/index.js +128 -99
- package/lib/DTableFiltersPopover/widgets/collaborator-filter/index.js +34 -26
- package/lib/DTableFiltersPopover/widgets/department-select-filter/department-multiple-select-filter.js +33 -25
- package/lib/DTableFiltersPopover/widgets/department-select-filter/department-single-select-filter.js +34 -26
- package/lib/DTableFiltersPopover/widgets/filter-calendar.js +34 -26
- package/lib/DTableFiltersPopover/widgets/filter-item.js +128 -120
- package/lib/DTableFiltersPopover/widgets/filter-list/index.css +21 -0
- package/lib/DTableFiltersPopover/widgets/filter-list/index.js +26 -18
- package/lib/DTableFiltersPopover/widgets/rate-item.js +15 -8
- package/lib/DTablePopover/index.js +15 -8
- package/lib/DTablePopover/utils.js +9 -2
- package/lib/DTableRadio/index.js +17 -10
- package/lib/DTableSearchInput/index.js +21 -13
- package/lib/DTableSearchInput/utils.js +9 -2
- package/lib/DTableSelect/dtable-select-label.js +13 -6
- package/lib/DTableSelect/index.js +18 -10
- package/lib/DTableSelect/utils.js +20 -10
- package/lib/DTableSwitch/index.js +14 -7
- package/lib/DateEditor/index.js +30 -22
- package/lib/DateEditor/mb-date-editor-popover/index.js +55 -47
- package/lib/DateEditor/pc-date-editor-popover.js +27 -20
- package/lib/DateFormatter/index.js +16 -9
- package/lib/Department-editor/constants.js +7 -1
- package/lib/Department-editor/department-multiple-select/index.js +32 -24
- package/lib/Department-editor/department-single-select.js +41 -33
- package/lib/Department-editor/index.js +22 -14
- package/lib/Department-editor/selected-departments/index.js +32 -25
- package/lib/Department-editor/utils.js +11 -3
- package/lib/DepartmentSingleSelectFormatter/index.js +16 -9
- package/lib/DigitalSignFormatter/index.js +23 -15
- package/lib/DigitalSignFormatter/utils.js +11 -3
- package/lib/DurationFormatter/index.js +16 -9
- package/lib/EditEditorButton/index.js +12 -5
- package/lib/EmailFormatter/index.js +14 -7
- package/lib/FieldDisplaySetting/field-item.js +21 -14
- package/lib/FieldDisplaySetting/index.js +27 -19
- package/lib/FileEditor/index.js +15 -8
- package/lib/FileEditor/pc-files-addition/index.js +1 -0
- package/lib/FileEditor/pc-files-addition/pc-file-uploaded-item.js +1 -0
- package/lib/FileEditor/pc-files-preview/index.js +1 -0
- package/lib/FileEditor/pc-files-preview/pc-file-item-preview.js +1 -0
- package/lib/FileFormatter/index.js +19 -11
- package/lib/FileItemFormatter/index.js +14 -6
- package/lib/FileItemFormatter/utils.js +9 -2
- package/lib/FileUploader/index.js +11 -4
- package/lib/FormulaFormatter/cell-value-validator.js +24 -18
- package/lib/FormulaFormatter/index.js +39 -32
- package/lib/FormulaFormatter/utils.js +29 -13
- package/lib/GeolocationFormatter/index.js +16 -9
- package/lib/HtmlLongTextFormatter/index.js +17 -9
- package/lib/ImageFormatter/images-lazy-load.js +16 -9
- package/lib/ImageFormatter/index.js +24 -16
- package/lib/ImageFormatter/utils.js +9 -2
- package/lib/ImagePreviewerLightbox/index.js +19 -12
- package/lib/ImagePreviewerLightbox/utils.js +11 -3
- package/lib/LastModifierFormatter/index.js +19 -12
- package/lib/LinkEditor/index.js +33 -25
- package/lib/LinkEditor/link-editor-option.js +15 -8
- package/lib/LinkEditor/mb-link-editor-popover/index.js +30 -23
- package/lib/LinkEditor/pc-link-editor-popover/index.js +24 -17
- package/lib/LinkFormatter/index.js +20 -13
- package/lib/Loading/index.js +11 -4
- package/lib/LongTextFormatter/index.js +13 -6
- package/lib/MBEditorHeader/index.js +14 -7
- package/lib/MTimeFormatter/index.js +16 -9
- package/lib/ModalPortal/index.js +12 -5
- package/lib/MultipleSelectEditor/index.js +25 -17
- package/lib/MultipleSelectFormatter/index.js +17 -10
- package/lib/NotificationPopover/index.js +24 -16
- package/lib/NumberEditor/index.js +25 -18
- package/lib/NumberFormatter/index.js +16 -9
- package/lib/RateFormatter/index.js +15 -8
- package/lib/RoleStatusEditor/index.js +22 -14
- package/lib/RowExpandEmailFormatter/index.js +17 -10
- package/lib/RowExpandFileFormatter/index.js +16 -8
- package/lib/RowExpandFileFormatter/row-expand-file-item-formatter.js +27 -18
- package/lib/RowExpandFormatter/index.js +86 -78
- package/lib/RowExpandFormulaFormatter/index.js +42 -34
- package/lib/RowExpandImageFormatter/index.js +19 -10
- package/lib/RowExpandImageFormatter/row-expand-image-item-formatter.js +27 -18
- package/lib/RowExpandImageFormatter/utils.js +9 -2
- package/lib/RowExpandLinkFormatter/collaborator-item-formatter.js +16 -7
- package/lib/RowExpandLinkFormatter/index.js +46 -37
- package/lib/RowExpandLinkFormatter/utils.js +17 -6
- package/lib/RowExpandLinkFormatter/value-display-utils.js +12 -5
- package/lib/RowExpandRateFormatter/index.js +15 -8
- package/lib/RowExpandUrlFormatter/index.js +21 -14
- package/lib/SelectItem/index.js +12 -4
- package/lib/SelectOptionGroup/KeyCodes.js +7 -1
- package/lib/SelectOptionGroup/index.js +28 -20
- package/lib/SelectOptionGroup/option.js +11 -4
- package/lib/SimpleLongTextFormatter/index.js +27 -20
- package/lib/SimpleLongTextFormatter/normalize-long-text-value.js +7 -1
- package/lib/SimpleLongTextFormatter/widgets/LongTextPreview.js +15 -8
- package/lib/SimpleLongTextFormatter/widgets/dtable-markdown-viewer.js +14 -7
- package/lib/SingleSelectEditor/index.js +26 -18
- package/lib/SingleSelectFormatter/index.js +16 -9
- package/lib/TextEditor/index.js +14 -7
- package/lib/TextFormatter/index.js +14 -7
- package/lib/UrlFormatter/index.js +14 -7
- package/lib/cellFormatterFactory/index.js +11 -4
- package/lib/common/ClickOutside.js +12 -4
- package/lib/common/delete-tip.js +20 -12
- package/lib/common/modal-portal.js +13 -5
- package/lib/constants/index.js +28 -9
- package/lib/data/dtable-value.js +11 -6
- package/lib/formatterConfig/base-formatter-config.js +53 -46
- package/lib/formatterConfig/index.js +16 -9
- package/lib/hooks/common-hooks.js +11 -4
- package/lib/index.js +432 -75
- package/lib/lang/index.js +24 -13
- package/lib/locals/de.js +7 -1
- package/lib/locals/en.js +7 -1
- package/lib/locals/fr.js +7 -1
- package/lib/locals/zh-CN.js +7 -1
- package/lib/select-editor/index.js +27 -4
- package/lib/select-editor/mb-select-editor-popover/index.js +41 -33
- package/lib/select-editor/pc-select-editor-popover/index.js +26 -19
- package/lib/select-editor/select-editor-option.js +15 -8
- package/lib/toaster/alert.js +18 -11
- package/lib/toaster/index.js +10 -3
- package/lib/toaster/toast.js +16 -8
- package/lib/toaster/toastManager.js +13 -5
- package/lib/toaster/toaster.js +15 -7
- package/lib/utils/dayjs.js +11 -4
- package/lib/utils/editor-utils.js +15 -5
- package/lib/utils/event-bus.js +7 -1
- package/lib/utils/utils.js +17 -6
- package/package.json +63 -77
- package/lib/HtmlLongTextFormatter/markdown2html.js +0 -47
- package/lib/HtmlLongTextFormatter/unified/index.js +0 -400
- package/lib/HtmlLongTextFormatter/vfile/core.js +0 -155
- package/lib/HtmlLongTextFormatter/vfile/index.js +0 -40
package/package.json
CHANGED
|
@@ -1,39 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dtable-ui-component",
|
|
3
|
-
"version": "4.4.2",
|
|
3
|
+
"version": "4.4.3-2",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@seafile/react-image-lightbox": "2.0.5",
|
|
7
7
|
"@seafile/seafile-calendar": "0.0.24",
|
|
8
8
|
"@seafile/seafile-editor": "0.3.146",
|
|
9
9
|
"antd-mobile": "2.3.1",
|
|
10
|
-
"bail": "1.0.5",
|
|
11
10
|
"classnames": "^2.3.2",
|
|
12
11
|
"dayjs": "1.10.7",
|
|
13
|
-
"deepmerge": "^2.1.0",
|
|
14
12
|
"dtable-utils": "4.4.0",
|
|
15
|
-
"hast-util-sanitize": "^1.1.2",
|
|
16
|
-
"hast-util-to-html": "3.1.0",
|
|
17
13
|
"is-hotkey": "0.2.0",
|
|
18
14
|
"react": "17.0.2",
|
|
19
15
|
"react-app-polyfill": "^3.0.0",
|
|
20
16
|
"react-dom": "17.0.2",
|
|
21
17
|
"react-responsive": "9.0.2",
|
|
22
18
|
"react-select": "5.7.0",
|
|
23
|
-
"react-transition-group": "^4.4.1"
|
|
24
|
-
"reactstrap": "8.9.0",
|
|
25
|
-
"rehype-format": "^2.2.0",
|
|
26
|
-
"rehype-mathjax": "^2.0.0",
|
|
27
|
-
"rehype-raw": "^2.0.0",
|
|
28
|
-
"remark-breaks": "^1.0.0",
|
|
29
|
-
"remark-math": "^3.0.0",
|
|
30
|
-
"remark-parse": "^5.0.0",
|
|
31
|
-
"remark-rehype": "^3.0.0",
|
|
32
|
-
"remark-slug": "^5.0.0",
|
|
33
|
-
"trough": "1.0.5",
|
|
34
|
-
"vfile": "2.3.0",
|
|
35
|
-
"x-is-string": "0.1.0",
|
|
36
|
-
"xtend": "^4.0.1"
|
|
19
|
+
"react-transition-group": "^4.4.1"
|
|
37
20
|
},
|
|
38
21
|
"scripts": {
|
|
39
22
|
"lint": "./node_modules/.bin/eslint ./src/ --fix",
|
|
@@ -73,13 +56,11 @@
|
|
|
73
56
|
]
|
|
74
57
|
},
|
|
75
58
|
"devDependencies": {
|
|
76
|
-
"@babel/cli": "
|
|
77
|
-
"@babel/core": "^7.
|
|
78
|
-
"@babel/
|
|
79
|
-
"@babel/plugin-proposal-
|
|
80
|
-
"@babel/plugin-
|
|
81
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.9.5",
|
|
82
|
-
"@babel/plugin-transform-runtime": "^7.10.1",
|
|
59
|
+
"@babel/cli": "7.22.15",
|
|
60
|
+
"@babel/core": "^7.16.0",
|
|
61
|
+
"@babel/eslint-parser": "^7.16.3",
|
|
62
|
+
"@babel/plugin-proposal-private-property-in-object": "7.21.11",
|
|
63
|
+
"@babel/plugin-transform-runtime": "7.22.10",
|
|
83
64
|
"@babel/polyfill": "^7.10.1",
|
|
84
65
|
"@babel/preset-env": "^7.9.5",
|
|
85
66
|
"@storybook/addon-actions": "^5.3.14",
|
|
@@ -88,66 +69,71 @@
|
|
|
88
69
|
"@storybook/addon-links": "^5.3.14",
|
|
89
70
|
"@storybook/addons": "^5.3.14",
|
|
90
71
|
"@storybook/react": "^7.5.0",
|
|
91
|
-
"@
|
|
92
|
-
"@
|
|
93
|
-
"@
|
|
94
|
-
"@testing-library/
|
|
95
|
-
"@
|
|
96
|
-
"@
|
|
97
|
-
"@
|
|
98
|
-
"
|
|
99
|
-
"babel-jest": "^
|
|
100
|
-
"babel-loader": "8.
|
|
72
|
+
"@babel/runtime": "7.22.11",
|
|
73
|
+
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.3",
|
|
74
|
+
"@svgr/webpack": "8.1.0",
|
|
75
|
+
"@testing-library/jest-dom": "5.17.0",
|
|
76
|
+
"@testing-library/react": "^11.1.0",
|
|
77
|
+
"@testing-library/user-event": "13.5.0",
|
|
78
|
+
"@types/jest": "^29.5.10",
|
|
79
|
+
"autoprefixer": "10.4.5",
|
|
80
|
+
"babel-jest": "^27.4.2",
|
|
81
|
+
"babel-loader": "^8.2.3",
|
|
101
82
|
"babel-plugin-import": "^1.13.6",
|
|
102
83
|
"babel-plugin-named-asset-import": "^0.3.6",
|
|
103
|
-
"babel-preset-react-app": "^
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
84
|
+
"babel-preset-react-app": "^10.0.1",
|
|
85
|
+
"bfj": "^7.0.2",
|
|
86
|
+
"browserslist": "^4.18.1",
|
|
87
|
+
"camelcase": "^6.2.1",
|
|
88
|
+
"case-sensitive-paths-webpack-plugin": "^2.4.0",
|
|
89
|
+
"circular-dependency-plugin": "^5.2.2",
|
|
90
|
+
"css-loader": "^6.5.1",
|
|
91
|
+
"css-minimizer-webpack-plugin": "^3.2.0",
|
|
92
|
+
"dotenv": "^10.0.0",
|
|
93
|
+
"dotenv-expand": "^5.1.0",
|
|
109
94
|
"enzyme": "^3.11.0",
|
|
110
|
-
"eslint": "^
|
|
111
|
-
"eslint-config-react-app": "^
|
|
112
|
-
"eslint-
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
"eslint-plugin-react": "7.18.0",
|
|
117
|
-
"eslint-plugin-react-hooks": "^1.6.1",
|
|
118
|
-
"file-loader": "4.3.0",
|
|
119
|
-
"fs-extra": "^8.1.0",
|
|
120
|
-
"html-webpack-plugin": "4.0.0-beta.11",
|
|
95
|
+
"eslint": "^8.3.0",
|
|
96
|
+
"eslint-config-react-app": "^7.0.1",
|
|
97
|
+
"eslint-webpack-plugin": "^3.1.1",
|
|
98
|
+
"file-loader": "^6.2.0",
|
|
99
|
+
"fs-extra": "^10.0.0",
|
|
100
|
+
"html-webpack-plugin": "^5.5.0",
|
|
121
101
|
"i18next": "22.4.9",
|
|
122
102
|
"i18next-browser-languagedetector": "7.0.1",
|
|
123
103
|
"i18next-xhr-backend": "3.2.2",
|
|
124
104
|
"identity-obj-proxy": "3.0.0",
|
|
125
|
-
"jest": "
|
|
126
|
-
"jest-
|
|
127
|
-
"jest-
|
|
128
|
-
"
|
|
129
|
-
"
|
|
130
|
-
"
|
|
131
|
-
"
|
|
132
|
-
"postcss
|
|
133
|
-
"postcss-
|
|
134
|
-
"postcss-
|
|
135
|
-
"postcss-
|
|
136
|
-
"postcss-
|
|
105
|
+
"jest": "^27.4.3",
|
|
106
|
+
"jest-resolve": "^27.4.2",
|
|
107
|
+
"jest-watch-typeahead": "^1.0.0",
|
|
108
|
+
"less": "^4.2.0",
|
|
109
|
+
"less-loader": "^11.1.3",
|
|
110
|
+
"mini-css-extract-plugin": "^2.4.5",
|
|
111
|
+
"node-polyfill-webpack-plugin": "2.0.1",
|
|
112
|
+
"postcss": "^8.4.31",
|
|
113
|
+
"postcss-flexbugs-fixes": "^5.0.2",
|
|
114
|
+
"postcss-loader": "^6.2.1",
|
|
115
|
+
"postcss-normalize": "^10.0.1",
|
|
116
|
+
"postcss-preset-env": "^7.0.1",
|
|
117
|
+
"prompts": "^2.4.2",
|
|
118
|
+
"react-app-polyfill": "^3.0.0",
|
|
137
119
|
"react-dev-utils": "^12.0.1",
|
|
120
|
+
"react-refresh": "^0.11.0",
|
|
138
121
|
"react-element-to-jsx-string": "^14.3.1",
|
|
139
122
|
"react-i18next": "12.1.4",
|
|
140
|
-
"resolve": "1.
|
|
141
|
-
"resolve-url-loader": "
|
|
142
|
-
"sass-loader": "
|
|
143
|
-
"semver": "
|
|
144
|
-
"
|
|
145
|
-
"
|
|
146
|
-
"
|
|
147
|
-
"
|
|
148
|
-
"
|
|
149
|
-
"
|
|
150
|
-
"webpack
|
|
151
|
-
"
|
|
123
|
+
"resolve": "^1.20.0",
|
|
124
|
+
"resolve-url-loader": "^4.0.0",
|
|
125
|
+
"sass-loader": "^12.3.0",
|
|
126
|
+
"semver": "^7.3.5",
|
|
127
|
+
"source-map-loader": "^3.0.0",
|
|
128
|
+
"style-loader": "^3.3.1",
|
|
129
|
+
"tailwindcss": "^3.0.2",
|
|
130
|
+
"terser-webpack-plugin": "^5.2.5",
|
|
131
|
+
"url-loader": "^4.1.1",
|
|
132
|
+
"web-vitals": "2.1.4",
|
|
133
|
+
"webpack": "^5.64.4",
|
|
134
|
+
"webpack-dev-server": "^4.6.0",
|
|
135
|
+
"webpack-manifest-plugin": "^4.0.2",
|
|
136
|
+
"workbox-webpack-plugin": "^6.4.1",
|
|
137
|
+
"worker-loader": "3.0.8"
|
|
152
138
|
}
|
|
153
139
|
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
var markdown = require('remark-parse');
|
|
2
|
-
var slug = require('remark-slug');
|
|
3
|
-
var breaks = require('remark-breaks');
|
|
4
|
-
var remark2rehype = require('remark-rehype');
|
|
5
|
-
var format = require('rehype-format');
|
|
6
|
-
var raw = require('rehype-raw');
|
|
7
|
-
var xtend = require('xtend');
|
|
8
|
-
var toHTML = require('hast-util-to-html');
|
|
9
|
-
var sanitize = require('hast-util-sanitize');
|
|
10
|
-
var gh = require('hast-util-sanitize/lib/github');
|
|
11
|
-
var deepmerge = require('deepmerge').default;
|
|
12
|
-
const mathjax = require('rehype-mathjax/browser');
|
|
13
|
-
const math = require('remark-math/block');
|
|
14
|
-
var unified = require('./unified').default;
|
|
15
|
-
function stringify(config) {
|
|
16
|
-
var settings = xtend(config, this.data('settings'));
|
|
17
|
-
var schema = deepmerge(gh, {
|
|
18
|
-
'attributes': {
|
|
19
|
-
'input': ['type'],
|
|
20
|
-
'li': ['className'],
|
|
21
|
-
'code': ['className'],
|
|
22
|
-
'span': ['className'],
|
|
23
|
-
'div': ['className']
|
|
24
|
-
},
|
|
25
|
-
'tagNames': ['input', 'code', 'span', 'div']
|
|
26
|
-
});
|
|
27
|
-
this.Compiler = compiler;
|
|
28
|
-
function compiler(tree) {
|
|
29
|
-
// use sanity to remove dangerous html, the default is
|
|
30
|
-
// GitHub style sanitation
|
|
31
|
-
var hast = sanitize(tree, schema);
|
|
32
|
-
return toHTML(hast, settings);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// markdown -> mdast -> html AST -> html
|
|
37
|
-
var processor = unified().use(markdown, {
|
|
38
|
-
commonmark: true
|
|
39
|
-
}).use(math).use(breaks).use(slug).use(remark2rehype, {
|
|
40
|
-
allowDangerousHTML: true
|
|
41
|
-
}).use(mathjax, {
|
|
42
|
-
displayMath: ['$$', '$$']
|
|
43
|
-
}).use(raw).use(format).use(stringify);
|
|
44
|
-
var processorGetAST = unified().use(markdown, {
|
|
45
|
-
commonmark: true
|
|
46
|
-
}).use(slug);
|
|
47
|
-
export { processor, processorGetAST };
|
|
@@ -1,400 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
/* Dependencies. */
|
|
5
|
-
var extend = require('extend');
|
|
6
|
-
var bail = require('bail');
|
|
7
|
-
var trough = require('trough');
|
|
8
|
-
var string = require('x-is-string');
|
|
9
|
-
var plain = require('is-plain-obj');
|
|
10
|
-
var vfile = require('../vfile').default;
|
|
11
|
-
var slice = [].slice;
|
|
12
|
-
var own = {}.hasOwnProperty;
|
|
13
|
-
|
|
14
|
-
/* Process pipeline. */
|
|
15
|
-
var pipeline = trough().use(pipelineParse).use(pipelineRun).use(pipelineStringify);
|
|
16
|
-
function pipelineParse(p, ctx) {
|
|
17
|
-
ctx.tree = p.parse(ctx.file);
|
|
18
|
-
}
|
|
19
|
-
function pipelineRun(p, ctx, next) {
|
|
20
|
-
p.run(ctx.tree, ctx.file, done);
|
|
21
|
-
function done(err, tree, file) {
|
|
22
|
-
if (err) {
|
|
23
|
-
next(err);
|
|
24
|
-
} else {
|
|
25
|
-
ctx.tree = tree;
|
|
26
|
-
ctx.file = file;
|
|
27
|
-
next();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function pipelineStringify(p, ctx) {
|
|
32
|
-
ctx.file.contents = p.stringify(ctx.tree, ctx.file);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/* Function to create the first processor. */
|
|
36
|
-
function unified() {
|
|
37
|
-
var attachers = [];
|
|
38
|
-
var transformers = trough();
|
|
39
|
-
var namespace = {};
|
|
40
|
-
var frozen = false;
|
|
41
|
-
var freezeIndex = -1;
|
|
42
|
-
|
|
43
|
-
/* Data management. */
|
|
44
|
-
processor.data = data;
|
|
45
|
-
|
|
46
|
-
/* Lock. */
|
|
47
|
-
processor.freeze = freeze;
|
|
48
|
-
|
|
49
|
-
/* Plug-ins. */
|
|
50
|
-
processor.attachers = attachers;
|
|
51
|
-
processor.use = use;
|
|
52
|
-
|
|
53
|
-
/* API. */
|
|
54
|
-
processor.parse = parse;
|
|
55
|
-
processor.stringify = stringify;
|
|
56
|
-
processor.run = run;
|
|
57
|
-
processor.runSync = runSync;
|
|
58
|
-
processor.process = process;
|
|
59
|
-
processor.processSync = processSync;
|
|
60
|
-
|
|
61
|
-
/* Expose. */
|
|
62
|
-
return processor;
|
|
63
|
-
|
|
64
|
-
/* Create a new processor based on the processor
|
|
65
|
-
* in the current scope. */
|
|
66
|
-
function processor() {
|
|
67
|
-
var destination = unified();
|
|
68
|
-
var length = attachers.length;
|
|
69
|
-
var index = -1;
|
|
70
|
-
while (++index < length) {
|
|
71
|
-
destination.use.apply(null, attachers[index]);
|
|
72
|
-
}
|
|
73
|
-
destination.data(extend(true, {}, namespace));
|
|
74
|
-
return destination;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/* Freeze: used to signal a processor that has finished
|
|
78
|
-
* configuration.
|
|
79
|
-
*
|
|
80
|
-
* For example, take unified itself. It’s frozen.
|
|
81
|
-
* Plug-ins should not be added to it. Rather, it should
|
|
82
|
-
* be extended, by invoking it, before modifying it.
|
|
83
|
-
*
|
|
84
|
-
* In essence, always invoke this when exporting a
|
|
85
|
-
* processor. */
|
|
86
|
-
function freeze() {
|
|
87
|
-
var values;
|
|
88
|
-
var plugin;
|
|
89
|
-
var options;
|
|
90
|
-
var transformer;
|
|
91
|
-
if (frozen) {
|
|
92
|
-
return processor;
|
|
93
|
-
}
|
|
94
|
-
while (++freezeIndex < attachers.length) {
|
|
95
|
-
values = attachers[freezeIndex];
|
|
96
|
-
plugin = values[0];
|
|
97
|
-
options = values[1];
|
|
98
|
-
transformer = null;
|
|
99
|
-
if (options === false) {
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
if (options === true) {
|
|
103
|
-
values[1] = undefined;
|
|
104
|
-
}
|
|
105
|
-
transformer = plugin.apply(processor, values.slice(1));
|
|
106
|
-
if (typeof transformer === 'function') {
|
|
107
|
-
transformers.use(transformer);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
frozen = true;
|
|
111
|
-
freezeIndex = Infinity;
|
|
112
|
-
return processor;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/* Data management.
|
|
116
|
-
* Getter / setter for processor-specific informtion. */
|
|
117
|
-
function data(key, value) {
|
|
118
|
-
if (string(key)) {
|
|
119
|
-
/* Set `key`. */
|
|
120
|
-
if (arguments.length === 2) {
|
|
121
|
-
assertUnfrozen('data', frozen);
|
|
122
|
-
namespace[key] = value;
|
|
123
|
-
return processor;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/* Get `key`. */
|
|
127
|
-
return own.call(namespace, key) && namespace[key] || null;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/* Set space. */
|
|
131
|
-
if (key) {
|
|
132
|
-
assertUnfrozen('data', frozen);
|
|
133
|
-
namespace = key;
|
|
134
|
-
return processor;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/* Get space. */
|
|
138
|
-
return namespace;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/* Plug-in management.
|
|
142
|
-
*
|
|
143
|
-
* Pass it:
|
|
144
|
-
* * an attacher and options,
|
|
145
|
-
* * a preset,
|
|
146
|
-
* * a list of presets, attachers, and arguments (list
|
|
147
|
-
* of attachers and options). */
|
|
148
|
-
function use(value) {
|
|
149
|
-
var settings;
|
|
150
|
-
assertUnfrozen('use', frozen);
|
|
151
|
-
if (value === null || value === undefined) {
|
|
152
|
-
/* Empty */
|
|
153
|
-
} else if (typeof value === 'function') {
|
|
154
|
-
addPlugin.apply(null, arguments);
|
|
155
|
-
} else if (typeof value === 'object') {
|
|
156
|
-
if ('length' in value) {
|
|
157
|
-
addList(value);
|
|
158
|
-
} else {
|
|
159
|
-
addPreset(value);
|
|
160
|
-
}
|
|
161
|
-
} else {
|
|
162
|
-
throw new Error('Expected usable value, not `' + value + '`');
|
|
163
|
-
}
|
|
164
|
-
if (settings) {
|
|
165
|
-
namespace.settings = extend(namespace.settings || {}, settings);
|
|
166
|
-
}
|
|
167
|
-
return processor;
|
|
168
|
-
function addPreset(result) {
|
|
169
|
-
addList(result.plugins);
|
|
170
|
-
if (result.settings) {
|
|
171
|
-
settings = extend(settings || {}, result.settings);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
function add(value) {
|
|
175
|
-
if (typeof value === 'function') {
|
|
176
|
-
addPlugin(value);
|
|
177
|
-
} else if (typeof value === 'object') {
|
|
178
|
-
if ('length' in value) {
|
|
179
|
-
addPlugin.apply(null, value);
|
|
180
|
-
} else {
|
|
181
|
-
addPreset(value);
|
|
182
|
-
}
|
|
183
|
-
} else {
|
|
184
|
-
throw new Error('Expected usable value, not `' + value + '`');
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
function addList(plugins) {
|
|
188
|
-
var length;
|
|
189
|
-
var index;
|
|
190
|
-
if (plugins === null || plugins === undefined) {
|
|
191
|
-
/* Empty */
|
|
192
|
-
} else if (typeof plugins === 'object' && 'length' in plugins) {
|
|
193
|
-
length = plugins.length;
|
|
194
|
-
index = -1;
|
|
195
|
-
while (++index < length) {
|
|
196
|
-
add(plugins[index]);
|
|
197
|
-
}
|
|
198
|
-
} else {
|
|
199
|
-
throw new Error('Expected a list of plugins, not `' + plugins + '`');
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
function addPlugin(plugin, value) {
|
|
203
|
-
var entry = find(plugin);
|
|
204
|
-
if (entry) {
|
|
205
|
-
if (plain(entry[1]) && plain(value)) {
|
|
206
|
-
value = extend(entry[1], value);
|
|
207
|
-
}
|
|
208
|
-
entry[1] = value;
|
|
209
|
-
} else {
|
|
210
|
-
attachers.push(slice.call(arguments));
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
function find(plugin) {
|
|
215
|
-
var length = attachers.length;
|
|
216
|
-
var index = -1;
|
|
217
|
-
var entry;
|
|
218
|
-
while (++index < length) {
|
|
219
|
-
entry = attachers[index];
|
|
220
|
-
if (entry[0] === plugin) {
|
|
221
|
-
return entry;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/* Parse a file (in string or VFile representation)
|
|
227
|
-
* into a Unist node using the `Parser` on the
|
|
228
|
-
* processor. */
|
|
229
|
-
function parse(doc) {
|
|
230
|
-
var file = vfile(doc);
|
|
231
|
-
var Parser;
|
|
232
|
-
freeze();
|
|
233
|
-
Parser = processor.Parser;
|
|
234
|
-
assertParser('parse', Parser);
|
|
235
|
-
if (newable(Parser)) {
|
|
236
|
-
return new Parser(String(file), file).parse();
|
|
237
|
-
}
|
|
238
|
-
return Parser(String(file), file); // eslint-disable-line new-cap
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/* Run transforms on a Unist node representation of a file
|
|
242
|
-
* (in string or VFile representation), async. */
|
|
243
|
-
function run(node, file, cb) {
|
|
244
|
-
assertNode(node);
|
|
245
|
-
freeze();
|
|
246
|
-
if (!cb && typeof file === 'function') {
|
|
247
|
-
cb = file;
|
|
248
|
-
file = null;
|
|
249
|
-
}
|
|
250
|
-
if (!cb) {
|
|
251
|
-
return new Promise(executor);
|
|
252
|
-
}
|
|
253
|
-
executor(null, cb);
|
|
254
|
-
function executor(resolve, reject) {
|
|
255
|
-
transformers.run(node, vfile(file), done);
|
|
256
|
-
function done(err, tree, file) {
|
|
257
|
-
tree = tree || node;
|
|
258
|
-
if (err) {
|
|
259
|
-
reject(err);
|
|
260
|
-
} else if (resolve) {
|
|
261
|
-
resolve(tree);
|
|
262
|
-
} else {
|
|
263
|
-
cb(null, tree, file);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/* Run transforms on a Unist node representation of a file
|
|
270
|
-
* (in string or VFile representation), sync. */
|
|
271
|
-
function runSync(node, file) {
|
|
272
|
-
var complete = false;
|
|
273
|
-
var result;
|
|
274
|
-
run(node, file, done);
|
|
275
|
-
assertDone('runSync', 'run', complete);
|
|
276
|
-
return result;
|
|
277
|
-
function done(err, tree) {
|
|
278
|
-
complete = true;
|
|
279
|
-
bail(err);
|
|
280
|
-
result = tree;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/* Stringify a Unist node representation of a file
|
|
285
|
-
* (in string or VFile representation) into a string
|
|
286
|
-
* using the `Compiler` on the processor. */
|
|
287
|
-
function stringify(node, doc) {
|
|
288
|
-
var file = vfile(doc);
|
|
289
|
-
var Compiler;
|
|
290
|
-
freeze();
|
|
291
|
-
Compiler = processor.Compiler;
|
|
292
|
-
assertCompiler('stringify', Compiler);
|
|
293
|
-
assertNode(node);
|
|
294
|
-
if (newable(Compiler)) {
|
|
295
|
-
return new Compiler(node, file).compile();
|
|
296
|
-
}
|
|
297
|
-
return Compiler(node, file); // eslint-disable-line new-cap
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/* Parse a file (in string or VFile representation)
|
|
301
|
-
* into a Unist node using the `Parser` on the processor,
|
|
302
|
-
* then run transforms on that node, and compile the
|
|
303
|
-
* resulting node using the `Compiler` on the processor,
|
|
304
|
-
* and store that result on the VFile. */
|
|
305
|
-
function process(doc, cb) {
|
|
306
|
-
freeze();
|
|
307
|
-
assertParser('process', processor.Parser);
|
|
308
|
-
assertCompiler('process', processor.Compiler);
|
|
309
|
-
if (!cb) {
|
|
310
|
-
return new Promise(executor);
|
|
311
|
-
}
|
|
312
|
-
executor(null, cb);
|
|
313
|
-
function executor(resolve, reject) {
|
|
314
|
-
var file = vfile(doc);
|
|
315
|
-
pipeline.run(processor, {
|
|
316
|
-
file: file
|
|
317
|
-
}, done);
|
|
318
|
-
function done(err) {
|
|
319
|
-
if (err) {
|
|
320
|
-
reject(err);
|
|
321
|
-
} else if (resolve) {
|
|
322
|
-
resolve(file);
|
|
323
|
-
} else {
|
|
324
|
-
cb(null, file);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/* Process the given document (in string or VFile
|
|
331
|
-
* representation), sync. */
|
|
332
|
-
function processSync(doc) {
|
|
333
|
-
var complete = false;
|
|
334
|
-
var file;
|
|
335
|
-
freeze();
|
|
336
|
-
assertParser('processSync', processor.Parser);
|
|
337
|
-
assertCompiler('processSync', processor.Compiler);
|
|
338
|
-
file = vfile(doc);
|
|
339
|
-
process(file, done);
|
|
340
|
-
assertDone('processSync', 'process', complete);
|
|
341
|
-
return file;
|
|
342
|
-
function done(err) {
|
|
343
|
-
complete = true;
|
|
344
|
-
bail(err);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/* Check if `func` is a constructor. */
|
|
350
|
-
function newable(value) {
|
|
351
|
-
return typeof value === 'function' && keys(value.prototype);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/* Check if `value` is an object with keys. */
|
|
355
|
-
function keys(value) {
|
|
356
|
-
var key;
|
|
357
|
-
for (key in value) {
|
|
358
|
-
return true;
|
|
359
|
-
}
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
/* Assert a parser is available. */
|
|
364
|
-
function assertParser(name, Parser) {
|
|
365
|
-
if (typeof Parser !== 'function') {
|
|
366
|
-
throw new Error('Cannot `' + name + '` without `Parser`');
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/* Assert a compiler is available. */
|
|
371
|
-
function assertCompiler(name, Compiler) {
|
|
372
|
-
if (typeof Compiler !== 'function') {
|
|
373
|
-
throw new Error('Cannot `' + name + '` without `Compiler`');
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
/* Assert the processor is not frozen. */
|
|
378
|
-
function assertUnfrozen(name, frozen) {
|
|
379
|
-
if (frozen) {
|
|
380
|
-
throw new Error(['Cannot invoke `' + name + '` on a frozen processor.\nCreate a new ', 'processor first, by invoking it: use `processor()` instead of ', '`processor`.'].join(''));
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/* Assert `node` is a Unist node. */
|
|
385
|
-
function assertNode(node) {
|
|
386
|
-
if (!node || !string(node.type)) {
|
|
387
|
-
throw new Error('Expected node, got `' + node + '`');
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
/* Assert that `complete` is `true`. */
|
|
392
|
-
function assertDone(name, asyncName, complete) {
|
|
393
|
-
if (!complete) {
|
|
394
|
-
throw new Error('`' + name + '` finished async. Use `' + asyncName + '` instead');
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/* Expose a frozen processor. */
|
|
399
|
-
const unified_freeze = unified().freeze();
|
|
400
|
-
export default unified_freeze;
|